mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #9278 from xiang90/jitter
v3rpc: add jitter to progress notification
This commit is contained in:
commit
c80ca24b54
@ -17,6 +17,7 @@ package v3rpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -57,8 +58,15 @@ var (
|
|||||||
|
|
||||||
func GetProgressReportInterval() time.Duration {
|
func GetProgressReportInterval() time.Duration {
|
||||||
progressReportIntervalMu.RLock()
|
progressReportIntervalMu.RLock()
|
||||||
defer progressReportIntervalMu.RUnlock()
|
interval := progressReportInterval
|
||||||
return 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) {
|
func SetProgressReportInterval(newTimeout time.Duration) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user