pub struct Limiter { /* private fields */ }Expand description
Per-channel adaptive limiter.
Cheap to clone — both fields are Arc. Pass clones into hot loops;
do not hold the lock across .await points (call sites observe
with short critical sections only).
Implementations§
Source§impl Limiter
impl Limiter
Sourcepub fn new(start: usize, config: LimiterConfig) -> Self
pub fn new(start: usize, config: LimiterConfig) -> Self
Create a new limiter starting at start, clamped into
[min_concurrency, max_concurrency]. Sanitizes the config to
guard against directly-constructed LimiterConfig literals
with hostile float values (NaN, etc).
Sourcepub fn current(&self) -> usize
pub fn current(&self) -> usize
Snapshot current concurrency cap. Hot-path call: the value may
change between this call and the next, but consumers
(buffer_unordered(n)) capture it once per pipeline build.
Sourcepub fn observe(&self, outcome: Outcome, latency: Duration)
pub fn observe(&self, outcome: Outcome, latency: Duration)
Record one observed operation. Updates the sliding window and re-evaluates the cap if the window is full enough.
Sourcepub fn warm_start(&self, start: usize)
pub fn warm_start(&self, start: usize)
Replace the current cap with start, clamped. Used for warm
loads from persisted state. Marks the limiter as having
already-left-slow-start so a single healthy window doesn’t
double the cap (an over-aggressive cold-start from a warm
value). Subsequent increases are +1 per healthy window.
Does not clear the sliding window — fresh observations remain
authoritative for adaptation decisions.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Limiter
impl RefUnwindSafe for Limiter
impl Send for Limiter
impl Sync for Limiter
impl Unpin for Limiter
impl UnsafeUnpin for Limiter
impl UnwindSafe for Limiter
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more