File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -208,14 +208,17 @@ func (d *driver) getScheme() string {
208
208
209
209
func getWaitDuration (backoff time.Duration , i int ) time.Duration {
210
210
// Strategy: after nth failed attempt, attempt resending after
211
- // k * initialBackoff, where k is a random number in range [0,
212
- // 2^n-1).
211
+ // k * initialBackoff + jitter, where k is a random number in
212
+ // range [0, 2^n-1), and jitter is a random percentage of
213
+ // initialBackoff from [-10%, 10%).
213
214
214
215
// There won't be an overflow, since i is capped to
215
216
// DefaultMaxAttempts (5).
216
217
upperK := (int64 )(1 ) << (i + 1 )
218
+ jitterPercent := (rand .Float64 () - 0.5 ) / 10.
219
+ jitter := jitterPercent * (float64 )(backoff )
217
220
k := rand .Int63n (upperK )
218
- return backoff * time .Duration ( k )
221
+ return ( time . Duration )( k ) * backoff + ( time .Duration )( jitter )
219
222
}
220
223
221
224
func (d * driver ) contextWithStop (ctx context.Context ) (context.Context , context.CancelFunc ) {
You can’t perform that action at this time.
0 commit comments