pub struct Jitter { /* private fields */ }
Expand description
An interval specification for deviating from the nominal wait time.
Jitter can be added to wait time Duration
s to ensure that multiple tasks waiting on the same
rate limit don’t wake up at the same time and attempt to measure at the same time.
Methods on rate limiters that work asynchronously like
DirectRateLimiter.until_ready_with_jitter
exist to automatically apply jitter to wait periods, thereby reducing the chance of a
thundering herd problem.
Examples
Jitter can be added manually to a Duration
:
let reference = Duration::from_secs(24);
let jitter = Jitter::new(Duration::from_secs(1), Duration::from_secs(1));
let result = jitter + reference;
assert!(result >= reference + Duration::from_secs(1));
assert!(result < reference + Duration::from_secs(2))
In a std
build (the default), Jitter can also be added to an Instant
:
let reference = Instant::now();
let jitter = Jitter::new(Duration::from_secs(1), Duration::from_secs(1));
let result = jitter + reference;
assert!(result >= reference + Duration::from_secs(1));
assert!(result < reference + Duration::from_secs(2))
Implementations
sourceimpl Jitter
impl Jitter
Trait Implementations
impl Copy for Jitter
impl StructuralPartialEq for Jitter
Auto Trait Implementations
impl RefUnwindSafe for Jitter
impl Send for Jitter
impl Sync for Jitter
impl Unpin for Jitter
impl UnwindSafe for Jitter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more