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§
Trait Implementations§
source§impl PartialEq for Jitter
impl PartialEq for Jitter
impl Copy for Jitter
impl Eq for Jitter
impl StructuralPartialEq for Jitter
Auto Trait Implementations§
impl Freeze for Jitter
impl RefUnwindSafe for Jitter
impl Send for Jitter
impl Sync for Jitter
impl Unpin for Jitter
impl UnwindSafe for Jitter
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)