From 142bff89f4fc4b89ae3048f3afba9d65b4df5f3d 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/etcdserver/api/v3rpc/watch.go b/etcdserver/api/v3rpc/watch.go index 65ad02d13..646d70f9f 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" @@ -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) {