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>
impl AdaptiveLimiter<Infallible>
Sourcepub fn builder() -> AdaptiveLimiterBuilder
pub fn builder() -> AdaptiveLimiterBuilder
Starts building an adaptive limiter.
Source§impl<S, C> AdaptiveLimiter<S, C>
impl<S, C> AdaptiveLimiter<S, C>
Sourcepub fn with_clock<C2>(self, clock: C2) -> AdaptiveLimiter<S, C2>
pub fn with_clock<C2>(self, clock: C2) -> AdaptiveLimiter<S, C2>
Replaces the time source (used to measure round-trip time), for deterministic tests. Resets the limiter.
Sourcepub fn current_limit(&self) -> u32
pub fn current_limit(&self) -> u32
The current concurrency limit.
Sourcepub fn try_acquire(&self) -> Option<AdaptivePermit<'_, S, C>>
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>
impl<S, C> AdaptiveLimiter<S, C>
Sourcepub async fn acquire(&self) -> AdaptivePermit<'_, S, C>
Available on crate feature runtime only.
pub async fn acquire(&self) -> AdaptivePermit<'_, S, C>
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>where
S: RefUnwindSafe,
C: RefUnwindSafe,
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more