Skip to content

Commit

Permalink
Spread out first call of filestore sync intervals
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Oct 31, 2024
1 parent 601ec42 commit 886e9ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"io"
"io/fs"
"math"
mrand "math/rand/v2"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -7946,7 +7947,11 @@ func (fs *fileStore) setSyncTimer() {
if fs.syncTmr != nil {
fs.syncTmr.Reset(fs.fcfg.SyncInterval)
} else {
fs.syncTmr = time.AfterFunc(fs.fcfg.SyncInterval, fs.syncBlocks)
// First time this fires will be any time up to the fs.fcfg.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)
}
}

Expand Down

0 comments on commit 886e9ee

Please sign in to comment.