[−][src]Struct ratelimit_meter::algorithms::leaky_bucket::LeakyBucket
Implements the industry-standard leaky bucket rate-limiting as-a-meter. The bucket keeps a "fill height", pretending to drip steadily (which reduces the fill height), and increases the fill height with every cell that is found conforming. If cells would make the bucket overflow, they count as non-conforming.
Drip implementation
Instead of having a background task update the bucket's fill
level, this implementation re-computes the fill level of the
bucket on every call to check
and related
methods.
Wait time calculation
If the cell does not fit, this implementation computes the minimum wait time until the cell can be accommodated. This minimum wait time does not account for thundering herd effects or other problems in concurrent resource acquisition, so users of this library must take care to apply positive jitter to these wait times.
Example
let mut lb = DirectRateLimiter::<LeakyBucket>::per_second(nonzero!(2u32)); assert_eq!(Ok(()), lb.check());
Trait Implementations
impl<P: Relative> Algorithm<P> for LeakyBucket<P>
[src]
type BucketState = State<P>
The state of a single rate limiting bucket. Read more
type NegativeDecision = TooEarly<P>
The type returned when a rate limiting decision for a single cell is negative. Each rate limiting algorithm can decide to return the type that suits it best, but most algorithms' decisions also implement NonConformance
, to ease handling of how long to wait. Read more
fn construct(
capacity: NonZeroU32,
cell_weight: NonZeroU32,
per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
[src]
capacity: NonZeroU32,
cell_weight: NonZeroU32,
per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
fn test_n_and_update(
&self,
state: &Self::BucketState,
n: u32,
t0: P
) -> Result<(), NegativeMultiDecision<TooEarly<P>>>
[src]
&self,
state: &Self::BucketState,
n: u32,
t0: P
) -> Result<(), NegativeMultiDecision<TooEarly<P>>>
fn test_and_update(
&self,
state: &Self::BucketState,
at: P
) -> Result<(), Self::NegativeDecision>
[src]
&self,
state: &Self::BucketState,
at: P
) -> Result<(), Self::NegativeDecision>
Tests if a single cell can be accommodated in the rate limiter at the instant at
and updates the rate-limiter state to account for the weight of the cell. Read more
impl<P: Relative> RateLimitState<LeakyBucket<P>, P> for State<P>
[src]
impl<P: Absolute> RateLimitStateWithClock<LeakyBucket<P>, P> for State<P>
[src]
fn last_touched(&self, _params: &LeakyBucket<P>) -> P
[src]
impl<P: PartialEq + Relative> PartialEq<LeakyBucket<P>> for LeakyBucket<P>
[src]
fn eq(&self, other: &LeakyBucket<P>) -> bool
[src]
fn ne(&self, other: &LeakyBucket<P>) -> bool
[src]
impl<P: Clone + Relative> Clone for LeakyBucket<P>
[src]
fn clone(&self) -> LeakyBucket<P>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<P: Eq + Relative> Eq for LeakyBucket<P>
[src]
impl<P: Debug + Relative> Debug for LeakyBucket<P>
[src]
Auto Trait Implementations
impl<P> Send for LeakyBucket<P>
impl<P> Sync for LeakyBucket<P>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom 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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Rfn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto 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.