[−][src]Struct governor::Jitter
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
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.
fn add(self, rhs: Duration) -> Duration
[src]
impl Add<Instant> for Jitter
[src]
type Output = Instant
The resulting type after applying the +
operator.
fn add(self, rhs: Instant) -> Instant
[src]
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
impl RefUnwindSafe for Jitter
impl Send for Jitter
impl Sync for Jitter
impl Unpin for Jitter
impl UnwindSafe for Jitter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,