Skip to content
Snippets Groups Projects
Commit 117347ff authored by David Stainton's avatar David Stainton
Browse files

Improve exponential backoff

parent 4f2ba39e
No related branches found
No related tags found
6 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!371[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast,!354Channels impl,!340Project/channels,!338Xx 4055/channel identity tracking
......@@ -232,6 +232,17 @@ func (c *clientIDTracker) Start() (stoppable.Stoppable, error) {
return stopper, nil
}
func pow(base, exponent int) int {
if exponent == 0 {
return 1
}
result := base
for i := 2; i <= exponent; i++ {
result *= base
}
return result
}
// registrationWorker is meant to run in it's own goroutine
// periodically registering, getting a new lease.
func (c *clientIDTracker) registrationWorker(stopper *stoppable.Single) {
......@@ -244,12 +255,13 @@ func (c *clientIDTracker) registrationWorker(stopper *stoppable.Single) {
if time.Now().After(c.registrationDisk.GetLease().Add(-graceDuration)) {
err := c.register()
if err != nil {
backoffSeconds := int(math.Pow(float64(base), float64(exponent)))
backoffSeconds := pow(base, exponent)
if backoffSeconds > maxBackoff {
backoffSeconds = maxBackoff
} else {
exponent += 1
}
waitTime = time.Second * time.Duration(backoffSeconds)
exponent += 1
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment