v3rpc: add jitter to progress notification

release-3.4
Xiang 2018-02-05 10:26:03 -08:00
parent 07f9229731
commit 142bff89f4
1 changed files with 10 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package v3rpc
import (
"context"
"io"
"math/rand"
"sync"
"time"
@ -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) {