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 observe_with_bytes(
&self,
outcome: Outcome,
latency: Duration,
bytes: u64,
)
pub fn observe_with_bytes( &self, outcome: Outcome, latency: Duration, bytes: u64, )
Record one observed operation with a payload byte count. Bytes are used by the fetch hill climber; AIMD channels ignore them.
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. Does not clear the sliding window —
fresh observations remain authoritative for adaptation
decisions.
Slow-start state after a warm load depends on the channel’s
slow_start_ramp_threshold:
- Default (threshold 0, i.e. quote/store): mark slow-start as already-left so a single healthy window doesn’t double a learned warm value — an over-aggressive jump. Subsequent increases are +1 per healthy window.
- Protected (threshold > clamped, i.e. fetch below the ceiling):
keep slow-start armed. This is critical for the CLI usage
pattern where every
ant file downloadis a fresh process that warm-starts from the snapshot: if warm_start always exited slow-start, the fetch cap could only ever grow additively from the persisted value, which cannot climb back to the ceiling against an intermittent Decrease trickle (the exact pin-at-~20 behaviour observed on a fast-but-lossy VPS). Keeping slow-start armed lets the cap double back toward the capacity the connection can actually sustain.
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