Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak initial filestore sync timer #6128

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"io"
"io/fs"
"math"
mrand "math/rand/v2"
mrand "math/rand"
"net"
"os"
"path/filepath"
Expand Down 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.Int63n(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