pub enum Backoff {
Linear {
current: usize,
limit: usize,
},
Exponential {
current: usize,
limit: usize,
},
}Expand description
A stateful backoff strategy used to reduce CPU contention in busy-wait loops.
This enum encapsulates both the configuration and the current state of the backoff.
It uses “Full Jitter” to prevent “thundering herd” problems by picking a random
number of spins between 0 and the current limit.
Variants§
Linear
Linear growth: increases the maximum spin count by 1 each step until it hits the limit.
Fields
Exponential
Exponential growth: doubles the maximum spin count each step until it hits the limit.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub fn linear(limit: usize) -> Self
pub fn linear(limit: usize) -> Self
Creates a new linear backoff starting with a maximum spin of 1.
At each call to [backoff], the internal limit will increase by 1 until limit is reached.
Sourcepub fn exponential(limit: usize) -> Self
pub fn exponential(limit: usize) -> Self
Creates a new exponential backoff starting with a maximum spin of 1.
At each call to [backoff], the internal limit will double (multiplicative growth)
until limit is reached.
Trait Implementations§
impl Copy for Backoff
impl Eq for Backoff
impl StructuralPartialEq for Backoff
Auto Trait Implementations§
impl Freeze for Backoff
impl RefUnwindSafe for Backoff
impl Send for Backoff
impl Sync for Backoff
impl Unpin for Backoff
impl UnsafeUnpin for Backoff
impl UnwindSafe for Backoff
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.