Skip to content

Commit

Permalink
Tweak initial filestore sync timer
Browse files Browse the repository at this point in the history
Previously this was always firing at the exact interval. Then #6041
changed this so that the first firing was anytime between 1s and the
interval to spread out different stores. This tweaks it once more to
anytime between interval/2 and interval. It will still spread things
out a bit but hit the benchmarks a bit less badly.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Nov 14, 2024
1 parent da1dcda commit f04de9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8243,11 +8243,11 @@ func (fs *fileStore) setSyncTimer() {
if fs.syncTmr != nil {
fs.syncTmr.Reset(fs.fcfg.SyncInterval)
} else {
// First time this fires will be any time up to the fs.fcfg.SyncInterval,
// First time this fires will be between SyncInterval/2 and SyncInterval,
// so that different stores are spread out, rather than having many of
// them trying to all sync at once, causing blips and contending dios.
start := time.Duration(mrand.Int64N(int64(fs.fcfg.SyncInterval)))
fs.syncTmr = time.AfterFunc(min(start, time.Second), fs.syncBlocks)
start := (fs.fcfg.SyncInterval / 2) + (time.Duration(mrand.Int64N(int64(fs.fcfg.SyncInterval / 2))))
fs.syncTmr = time.AfterFunc(start, fs.syncBlocks)
}
}

Expand Down
8 changes: 8 additions & 0 deletions server/jetstream_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ func startJSClusterAndConnect(b *testing.B, clusterSize int) (c *cluster, s *Ser
shutdown = func() {
s.Shutdown()
}
s.optsMu.Lock()
s.opts.SyncInterval = 5 * time.Minute
s.optsMu.Unlock()
} else {
c = createJetStreamClusterExplicit(b, "BENCH_PUB", clusterSize)
c.waitOnClusterReadyWithNumPeers(clusterSize)
Expand All @@ -1768,6 +1771,11 @@ func startJSClusterAndConnect(b *testing.B, clusterSize int) (c *cluster, s *Ser
shutdown = func() {
c.shutdown()
}
for _, s := range c.servers {
s.optsMu.Lock()
s.opts.SyncInterval = 5 * time.Minute
s.optsMu.Unlock()
}
}

nc, err = nats.Connect(s.ClientURL())
Expand Down

0 comments on commit f04de9f

Please sign in to comment.