MCPcopy
hub / github.com/grafana/dskit / NextDelay

Method NextDelay

backoff/backoff.go:99–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97}
98
99func (b *Backoff) NextDelay() time.Duration {
100 b.numRetries++
101
102 // Handle the edge case where the min and max have the same value
103 // (or due to some misconfig max is < min)
104 if b.nextDelayMin >= b.nextDelayMax {
105 return b.nextDelayMin
106 }
107
108 // Add a jitter within the next exponential backoff range
109 sleepTime := b.nextDelayMin + time.Duration(rand.Int63n(int64(b.nextDelayMax-b.nextDelayMin)))
110
111 // Apply the exponential backoff to calculate the next jitter
112 // range, unless we've already reached the max
113 if b.nextDelayMax < b.cfg.MaxBackoff {
114 b.nextDelayMin = doubleDuration(b.nextDelayMin, b.cfg.MaxBackoff)
115 b.nextDelayMax = doubleDuration(b.nextDelayMax, b.cfg.MaxBackoff)
116 }
117
118 return sleepTime
119}
120
121func doubleDuration(value time.Duration, max time.Duration) time.Duration {
122 value = value * 2

Callers 2

WaitMethod · 0.95
TestBackoff_NextDelayFunction · 0.80

Calls 1

doubleDurationFunction · 0.85

Tested by 1

TestBackoff_NextDelayFunction · 0.64