pub struct HttpConnectionLimiter { /* private fields */ }Implementations§
Source§impl HttpConnectionLimiter
impl HttpConnectionLimiter
pub fn new(cap: usize) -> HttpConnectionLimiter
Sourcepub fn with_clock(
cap: usize,
clock: Arc<dyn MonotonicClock>,
) -> HttpConnectionLimiter
pub fn with_clock( cap: usize, clock: Arc<dyn MonotonicClock>, ) -> HttpConnectionLimiter
Construct with an explicit clock. Production uses [new], which
wires the real monotonic clock; tests inject a fake to drive the
rejection-rate derivation deterministically.
Sourcepub fn with_default_cap() -> HttpConnectionLimiter
pub fn with_default_cap() -> HttpConnectionLimiter
Default cap: (2 * available_parallelism).clamp(8, 256).
pub fn cap(&self) -> usize
pub fn current(&self) -> usize
Sourcepub fn try_acquire(&self) -> Option<HttpConnectionPermit>
pub fn try_acquire(&self) -> Option<HttpConnectionPermit>
Returns Some(permit) on success, None if the cap is full.
No blocking, no allocation on the hot path.
Sourcepub fn rejected_since_last_observe(&self) -> u64
pub fn rejected_since_last_observe(&self) -> u64
Rejections accumulated since the last observe.
Read-only: it accumulates monotonically within a window and is
reset only by observe.
Sourcepub fn observe(&self) -> LimiterObservation
pub fn observe(&self) -> LimiterObservation
Snapshot-and-reset the rejection window: returns the rejections
since the previous observe together with the elapsed wall and the
derived per-second rate, then resets the counter and arms the next
window at the current clock reading. rejections_per_sec is 0.0
when no time has elapsed (avoids a divide-by-zero on back-to-back
observes).
Trait Implementations§
Source§impl Clone for HttpConnectionLimiter
impl Clone for HttpConnectionLimiter
Source§fn clone(&self) -> HttpConnectionLimiter
fn clone(&self) -> HttpConnectionLimiter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HttpConnectionLimiter
impl !RefUnwindSafe for HttpConnectionLimiter
impl Send for HttpConnectionLimiter
impl Sync for HttpConnectionLimiter
impl Unpin for HttpConnectionLimiter
impl UnsafeUnpin for HttpConnectionLimiter
impl !UnwindSafe for HttpConnectionLimiter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request