ExponentialBackoff returns a duration for a reasonable exponential backoff interval for a service based on the given attempt number, which can then be fed into CancellableSleep to perform the sleep. Uses a 2**N second algorithm, +/- 10% random jitter. Sleep is cancelled if the given context is cance
(attempt, maxAttemptsBeforeReset int)
| 64 | // - 32s |
| 65 | // - 64s. |
| 66 | func ExponentialBackoff(attempt, maxAttemptsBeforeReset int) time.Duration { |
| 67 | retrySeconds := exponentialBackoffSecondsWithoutJitter(attempt, maxAttemptsBeforeReset) |
| 68 | |
| 69 | // Jitter number of seconds +/- 10%. |
| 70 | retrySeconds += retrySeconds * (rand.Float64()*0.2 - 0.1) |
| 71 | |
| 72 | return timeutil.SecondsAsDuration(retrySeconds) |
| 73 | } |
| 74 | |
| 75 | func exponentialBackoffSecondsWithoutJitter(attempt, maxAttemptsBeforeReset int) float64 { |
| 76 | // It's easier for callers and more intuitive if attempt starts at one, but |
searching dependent graphs…