[−][src]Struct governor::DirectRateLimiter
An in-memory rate limiter that makes direct (un-keyed) rate-limiting decisions. Direct rate limiters can be used to e.g. regulate the transmission of packets on a single connection, or to ensure that an API client stays within a service's rate limit.
Methods
impl DirectRateLimiter<MonotonicClock>
[src]
Methods that allow asynchronously waiting for the rate limit to clear.
pub async fn until_ready<'_>(&'_ self)
[src]
Asynchronously resolves as soon as the rate limiter allows it.
When polled, the returned future either resolves immediately (in the case where the rate limiter allows it), or else triggers an asynchronous delay, after which the rate limiter is polled again. This means that the future might resolve at some later time (depending on what other measurements are made on the rate limiter).
If multiple futures are dispatched against the rate limiter, it is advisable to use
until_ready_with_jitter
, to avoid thundering herds.
pub async fn until_ready_with_jitter<'_>(&'_ self, jitter: Jitter)
[src]
Asynchronously resolves as soon as the rate limiter allows it, with a randomized wait period.
When polled, the returned future either resolves immediately (in the case where the rate limiter allows it), or else triggers an asynchronous delay, after which the rate limiter is polled again. This means that the future might resolve at some later time (depending on what other measurements are made on the rate limiter).
This method allows for a randomized additional delay between polls of the rate limiter, which can help reduce the likelihood of thundering herd effects if multiple tasks try to wait on the same rate limiter.
impl DirectRateLimiter<DefaultClock>
[src]
The default constructor in std
mode.
pub fn new(quota: Quota) -> Self
[src]
Construct a new direct rate limiter for a quota with the default clock.
impl<C: Clock> DirectRateLimiter<C>
[src]
Manually checking cells against a rate limit.
pub fn check(&self) -> Result<(), NotUntil<C::Instant>>
[src]
Allow a single cell through the rate limiter.
If the rate limit is reached, check
returns information about the earliest
time that a cell might be allowed through again.
pub fn check_all(
&self,
n: NonZeroU32
) -> Result<(), NegativeMultiDecision<NotUntil<C::Instant>>>
[src]
&self,
n: NonZeroU32
) -> Result<(), NegativeMultiDecision<NotUntil<C::Instant>>>
Allow only all n
cells through the rate limiter.
This method can succeed in only one way and fail in two ways:
- Success: If all
n
cells can be accommodated, it returnsOk(())
. - Failure (but ok): Not all cells can make it through at the current time.
The result is
Err(NegativeMultiDecision::BatchNonConforming(NotUntil))
, which can be interrogated about when the batch might next conform. - Failure (the batch can never go through): The rate limit is too low for the given number of cells.
Performance
This method diverges a little from the GCRA algorithm, using multiplication to determine the next theoretical arrival time, and so is not as fast as checking a single cell.
impl<C: Clock> DirectRateLimiter<C>
[src]
pub fn new_with_clock(quota: Quota, clock: &C) -> DirectRateLimiter<C>
[src]
Construct a new direct rate limiter with a custom clock.
ⓘImportant traits for &'_ mut Wpub fn get_clock(&self) -> &C
[src]
Returns a reference to the rate limiter's clock.
Trait Implementations
Auto Trait Implementations
impl<C> Send for DirectRateLimiter<C> where
C: Send,
<C as Clock>::Instant: Send,
C: Send,
<C as Clock>::Instant: Send,
impl<C> Sync for DirectRateLimiter<C> where
C: Sync,
<C as Clock>::Instant: Sync,
C: Sync,
<C as Clock>::Instant: Sync,
impl<C> Unpin for DirectRateLimiter<C> where
C: Unpin,
<C as Clock>::Instant: Unpin,
C: Unpin,
<C as Clock>::Instant: Unpin,
impl<C> UnwindSafe for DirectRateLimiter<C> where
C: UnwindSafe,
<C as Clock>::Instant: UnwindSafe,
C: UnwindSafe,
<C as Clock>::Instant: UnwindSafe,
impl<C> RefUnwindSafe for DirectRateLimiter<C> where
C: RefUnwindSafe,
<C as Clock>::Instant: RefUnwindSafe,
C: RefUnwindSafe,
<C as Clock>::Instant: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Wfn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,