[][src]Struct governor::Jitter

pub struct Jitter { /* fields omitted */ }

An interval specification for deviating from the nominal wait time.

Jitter can be added to wait time Durations 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

impl Jitter[src]

pub fn up_to(max: Duration) -> Jitter[src]

Constructs a new Jitter interval, waiting at most a duration of max.

pub fn new(min: Duration, interval: Duration) -> Jitter[src]

Constructs a new Jitter interval, waiting at least min and at most min+interval.

Trait Implementations

impl Add<Duration> for Jitter[src]

type Output = Duration

The resulting type after applying the + operator.

impl Add<Instant> for Jitter[src]

type Output = Instant

The resulting type after applying the + operator.

impl Clone for Jitter[src]

impl Copy for Jitter[src]

impl Debug for Jitter[src]

impl Default for Jitter[src]

impl PartialEq<Jitter> for Jitter[src]

impl StructuralPartialEq for Jitter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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