pub struct RequestRateTracker { /* private fields */ }Expand description
Per-request rate tracker.
Not thread-safe — intended to be owned by a single request handler.
Callers needing concurrent access should wrap in a Mutex.
Implementations§
Source§impl RequestRateTracker
impl RequestRateTracker
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a tracker with default settings (window = 128 TBT samples, alpha = 0.20).
Sourcepub fn with_params(tbt_capacity: usize, alpha: f64) -> Self
pub fn with_params(tbt_capacity: usize, alpha: f64) -> Self
Create a tracker with custom parameters.
tbt_capacity is clamped to at least 1; alpha is clamped to
[0.0, 1.0].
Sourcepub fn record_admission(&mut self)
pub fn record_admission(&mut self)
Mark the request as admitted (e.g. dequeued from the request queue).
Sourcepub fn record_first_token(&mut self)
pub fn record_first_token(&mut self)
Mark the first token as emitted. This implicitly counts the token,
so callers should not also call record_token for the first token.
Sourcepub fn record_token(&mut self)
pub fn record_token(&mut self)
Mark a subsequent (non-first) token as emitted.
If record_first_token was never called, this also doubles as
the first-token marker.
Sourcepub fn snapshot(&self) -> RequestRateSnapshot
pub fn snapshot(&self) -> RequestRateSnapshot
Take a snapshot of the current state without disturbing the tracker.
Sourcepub fn queue_wait_seconds(&self) -> Option<f64>
pub fn queue_wait_seconds(&self) -> Option<f64>
Queue wait time (admission → first token), if both are recorded.
Sourcepub fn tokens_emitted(&self) -> u64
pub fn tokens_emitted(&self) -> u64
Number of tokens emitted so far.
Sourcepub fn tokens_per_second(&self) -> f64
pub fn tokens_per_second(&self) -> f64
EMA-smoothed tokens per second.
Trait Implementations§
Source§impl Clone for RequestRateTracker
impl Clone for RequestRateTracker
Source§fn clone(&self) -> RequestRateTracker
fn clone(&self) -> RequestRateTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RequestRateTracker
impl Debug for RequestRateTracker
Auto Trait Implementations§
impl Freeze for RequestRateTracker
impl RefUnwindSafe for RequestRateTracker
impl Send for RequestRateTracker
impl Sync for RequestRateTracker
impl Unpin for RequestRateTracker
impl UnsafeUnpin for RequestRateTracker
impl UnwindSafe for RequestRateTracker
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