From 1e9d1632aee025a2495fc006befeb060d2ac8ec5 Mon Sep 17 00:00:00 2001 From: Xiang Date: Mon, 5 Feb 2018 10:26:03 -0800 Subject: [PATCH] v3rpc: add jitter to progress notification --- etcdserver/api/v3rpc/watch.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/etcdserver/api/v3rpc/watch.go b/etcdserver/api/v3rpc/watch.go index 65ad02d13226..b80adf9db3f9 100644 --- a/etcdserver/api/v3rpc/watch.go +++ b/etcdserver/api/v3rpc/watch.go @@ -17,6 +17,7 @@ package v3rpc import ( "context" "io" + "math/rand" "sync" "time" @@ -56,9 +57,14 @@ var ( ) func GetProgressReportInterval() time.Duration { + // 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(progressReportInterval) / 10)) + progressReportIntervalMu.RLock() defer progressReportIntervalMu.RUnlock() - return progressReportInterval + return progressReportInterval + jitter } func SetProgressReportInterval(newTimeout time.Duration) {