Skip to content

Commit

Permalink
Merge pull request #9278 from xiang90/jitter
Browse files Browse the repository at this point in the history
v3rpc: add jitter to progress notification
  • Loading branch information
xiang90 authored Feb 5, 2018
2 parents 07f9229 + 142bff8 commit c80ca24
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v3rpc
import (
"context"
"io"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -57,8 +58,15 @@ var (

func GetProgressReportInterval() time.Duration {
progressReportIntervalMu.RLock()
defer progressReportIntervalMu.RUnlock()
return progressReportInterval
interval := progressReportInterval
progressReportIntervalMu.RUnlock()

// add rand(1/10*progressReportInterval) as jitter so that etcdserver will not
// send progress notifications to watchers around the same time even when watchers
// are created around the same time (which is common when a client restarts itself).
jitter := time.Duration(rand.Int63n(int64(interval) / 10))

return interval + jitter
}

func SetProgressReportInterval(newTimeout time.Duration) {
Expand Down

0 comments on commit c80ca24

Please sign in to comment.