Skip to content

Commit

Permalink
Add jitter for flushing stream state (#6220)
Browse files Browse the repository at this point in the history
`flushStreamStateLoop` would always run on the same interval for each
and every stream. Introduce jitter to spread out after restarts.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
  • Loading branch information
derekcollison authored Dec 5, 2024
2 parents 436340a + 455808b commit e59bb19
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 @@ -8270,8 +8270,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 e59bb19

Please sign in to comment.