Skip to content

Commit

Permalink
Add jitter for flushing stream state
Browse files Browse the repository at this point in the history
Signed-off-by: Maurice van Veen <[email protected]>
  • Loading branch information
MauriceVanVeen authored and wallyqs committed Dec 5, 2024
1 parent 5e757eb commit 716b139
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8157,8 +8157,10 @@ func (fs *fileStore) flushStreamStateLoop(qch, done chan struct{}) {
defer close(done)

// Make sure we do not try to write these out too fast.
// Spread these out for large numbers on a server restart.
const writeThreshold = 2 * time.Minute
t := time.NewTicker(writeThreshold)
writeJitter := time.Duration(mrand.Int63n(int64(30 * time.Second)))
t := time.NewTicker(writeThreshold + writeJitter)
defer t.Stop()

for {
Expand Down

0 comments on commit 716b139

Please sign in to comment.