chore(stdiscosrv): smooth retry-after delays over a slightly larger normal distribution

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-04-06 14:49:13 +02:00
parent 1d4df9c1f4
commit 3ac9b83f40
2 changed files with 61 additions and 1 deletions
+13 -1
View File
@@ -564,5 +564,17 @@ func (t *retryAfterTracker) retryAfterS() int {
}
t.curCount++
t.mut.Unlock()
return t.currentDelay + rand.Intn(t.currentDelay/4)
// Skewed normal distribution with the mean at currentDelay and the
// limits (50% and 150%) at 3 standard deviations
nf := rand.NormFloat64()
minD := max(notFoundRetryUnknownMinSeconds, t.currentDelay/2)
maxD := min(notFoundRetryUnknownMaxSeconds, t.currentDelay*3/2)
intv := float64(maxD - t.currentDelay)
if nf < 0 {
intv = float64(t.currentDelay - minD)
}
nf = min(max(nf*intv/3+float64(t.currentDelay), notFoundRetryUnknownMinSeconds), notFoundRetryUnknownMaxSeconds)
return int(nf)
}