Skip to main content

Backoff

Struct Backoff 

Source
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: Duration

Wait before the second attempt. Doubles from there.

§longest: Duration

Ceiling for the wait, before jitter.

§attempts: u32

How many attempts in total, including the first.

Implementations§

Source§

impl Backoff

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Backoff

Source§

fn clone(&self) -> Backoff

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Backoff

Source§

impl Debug for Backoff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Backoff

Source§

fn default() -> Self

A second, doubling, capped at thirty, giving up after ten attempts.

Ten attempts spans roughly four minutes, which covers a host restart without leaving a caller waiting on one that is never coming back.

Source§

impl Eq for Backoff

Source§

impl PartialEq for Backoff

Source§

fn eq(&self, other: &Backoff) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Backoff

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V