[−][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 Algorithm for LeakyBucket
[src]
impl Algorithm for LeakyBucket
type BucketState = State
The state of a single rate limiting bucket. Read more
type NegativeDecision = TooEarly
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]
fn construct(
capacity: NonZeroU32,
cell_weight: NonZeroU32,
per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
Constructs a rate limiter with the given parameters: capacity
is the number of cells to allow, weighing cell_weight
, every per_time_unit
. Read more
fn test_n_and_update(
&self,
state: &Self::BucketState,
n: u32,
t0: Instant
) -> Result<(), NegativeMultiDecision<TooEarly>>
[src]
fn test_n_and_update(
&self,
state: &Self::BucketState,
n: u32,
t0: Instant
) -> Result<(), NegativeMultiDecision<TooEarly>>
Tests if n
cells can be accommodated in the rate limiter at the instant at
and updates the rate-limiter state to account for the weight of the cells and updates the ratelimiter state. Read more
fn test_and_update(
&self,
state: &Self::BucketState,
at: Instant
) -> Result<(), Self::NegativeDecision>
[src]
fn test_and_update(
&self,
state: &Self::BucketState,
at: Instant
) -> 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 RateLimitState<LeakyBucket> for State
[src]
impl RateLimitState<LeakyBucket> for State
fn last_touched(&self, _params: &LeakyBucket) -> Instant
[src]
fn last_touched(&self, _params: &LeakyBucket) -> Instant
Returns the last time instant that the state had any relevance (i.e. the rate limiter would behave exactly as if it was a new rate limiter after this time). Read more
impl Clone for LeakyBucket
[src]
impl Clone for LeakyBucket
fn clone(&self) -> LeakyBucket
[src]
fn clone(&self) -> LeakyBucket
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq<LeakyBucket> for LeakyBucket
[src]
impl PartialEq<LeakyBucket> for LeakyBucket
fn eq(&self, other: &LeakyBucket) -> bool
[src]
fn eq(&self, other: &LeakyBucket) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &LeakyBucket) -> bool
[src]
fn ne(&self, other: &LeakyBucket) -> bool
This method tests for !=
.
impl Eq for LeakyBucket
[src]
impl Eq for LeakyBucket
impl Debug for LeakyBucket
[src]
impl Debug for LeakyBucket
Auto Trait Implementations
impl Send for LeakyBucket
impl Send for LeakyBucket
impl Sync for LeakyBucket
impl Sync for LeakyBucket
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
impl<T> Erased for T