pub struct Backoff {
pub first: Duration,
pub longest: Duration,
pub attempts: u32,
}Expand description
How hard to try when a host is not answering yet.
A host restarts, and every panel connected to it tries to come back. Without spreading those attempts out they arrive together and knock the host over again, so the delay grows and carries a random fraction. The growth stops a dead host being hammered; the randomness stops a live one being hit by a crowd.
Fields§
§first: DurationWait before the second attempt. Doubles from there.
longest: DurationCeiling for the wait, before jitter.
attempts: u32How many attempts in total, including the first.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub fn first_delay() -> Duration
pub fn first_delay() -> Duration
How long to wait before the very first attempt.
RFC 6455 section 7.2.3 asks for a random delay here specifically, and
suggests somewhere between zero and five seconds. This uses that range
rather than first, because the point is to scatter a
crowd of clients that all woke at once, not to pace one client’s
retries.
Sourcepub fn delay(self, attempt: u32) -> Duration
pub fn delay(self, attempt: u32) -> Duration
How long to wait before attempt attempt, counting the first as 0.
Doubling, capped, then up to a quarter added on top. The jitter comes from the clock rather than a random number generator, which keeps a dependency out for a value that only has to differ between processes.