Skip to main content

AdaptiveLimiter

Struct AdaptiveLimiter 

Source
pub struct AdaptiveLimiter<S, C = SystemClock>
where C: Clock,
{ /* private fields */ }
Available on crate feature adaptive only.
Expand description

A concurrency limiter whose in-flight limit adapts to observed outcomes.

Build one with AdaptiveLimiter::builder. Behind the adaptive feature.

§Examples

use throttle_net::{Aimd, AdaptiveLimiter};

let limiter = AdaptiveLimiter::builder()
    .floor(2)
    .ceiling(50)
    .initial(10)
    .build(Aimd::default());

if let Some(permit) = limiter.try_acquire() {
    // ... call the downstream, then report how it went ...
    let ok = true;
    if ok { permit.success() } else { permit.failure() }
}

Implementations§

Source§

impl AdaptiveLimiter<Infallible>

Source

pub fn builder() -> AdaptiveLimiterBuilder

Starts building an adaptive limiter.

Source§

impl<S, C> AdaptiveLimiter<S, C>
where S: AdaptiveStrategy, C: Clock + Clone,

Source

pub fn with_clock<C2>(self, clock: C2) -> AdaptiveLimiter<S, C2>
where C2: Clock + Clone,

Replaces the time source (used to measure round-trip time), for deterministic tests. Resets the limiter.

Source

pub fn current_limit(&self) -> u32

The current concurrency limit.

Source

pub fn in_flight(&self) -> u32

The number of requests currently in flight.

Source

pub fn ceiling(&self) -> u32

The hard ceiling the adapting limit can never exceed.

Source

pub fn try_acquire(&self) -> Option<AdaptivePermit<'_, S, C>>

Attempts to admit a request without waiting, returning a AdaptivePermit when a slot is free.

Source§

impl<S, C> AdaptiveLimiter<S, C>
where S: AdaptiveStrategy, C: Clock + Clone,

Source

pub async fn acquire(&self) -> AdaptivePermit<'_, S, C>

Available on crate feature runtime only.

Admits a request, waiting until a slot is free.

Unlike the rate limiters, this waits on a slot being released (or the limit growing), not on a timer. Returns a AdaptivePermit to settle with the request’s outcome.

Auto Trait Implementations§

§

impl<S, C = SystemClock> !Freeze for AdaptiveLimiter<S, C>

§

impl<S, C> RefUnwindSafe for AdaptiveLimiter<S, C>

§

impl<S, C> Send for AdaptiveLimiter<S, C>
where S: Send,

§

impl<S, C> Sync for AdaptiveLimiter<S, C>
where S: Sync,

§

impl<S, C> Unpin for AdaptiveLimiter<S, C>
where S: Unpin, C: Unpin,

§

impl<S, C> UnsafeUnpin for AdaptiveLimiter<S, C>
where S: UnsafeUnpin, C: UnsafeUnpin,

§

impl<S, C> UnwindSafe for AdaptiveLimiter<S, C>
where S: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more