Skip to content

Commit fa2f141

Browse files
authored
Spread the sync load over time (#1587)
* Spread the sync load over time Signed-off-by: Goutham Veeramachaneni <[email protected]> * Move seed to main Signed-off-by: Goutham Veeramachaneni <[email protected]>
1 parent 870fe73 commit fa2f141

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cmd/cortex/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"flag"
55
"fmt"
66
"io/ioutil"
7+
"math/rand"
78
"os"
89
"runtime"
10+
"time"
911

1012
"github.com/go-kit/kit/log/level"
1113
"github.com/pkg/errors"
@@ -57,6 +59,9 @@ func main() {
5759
trace := tracing.NewFromEnv("cortex-" + cfg.Target.String())
5860
defer trace.Close()
5961

62+
// Initialise seed for randomness usage.
63+
rand.Seed(time.Now().UnixNano())
64+
6065
t, err := cortex.New(cfg)
6166
util.CheckFatal("initializing cortex", err)
6267

pkg/chunk/table_manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8+
"math/rand"
89
"sort"
910
"strings"
1011
"sync"
@@ -166,6 +167,9 @@ func (m *TableManager) Stop() {
166167
func (m *TableManager) loop() {
167168
defer m.wait.Done()
168169

170+
// Sleep for a bit to spread the sync load across different times if the tablemanagers are all started at once.
171+
time.Sleep(time.Duration(rand.Int63n(int64(m.cfg.DynamoDBPollInterval))))
172+
169173
ticker := time.NewTicker(m.cfg.DynamoDBPollInterval)
170174
defer ticker.Stop()
171175

0 commit comments

Comments
 (0)