pub struct AutoThrottle { /* private fields */ }Available on crate feature
auto_throttle only.Expand description
Per-domain auto-throttle that dynamically computes crawl delay.
Thread-safe: DashMap for concurrent access, atomics for per-domain state.
Implementations§
Source§impl AutoThrottle
impl AutoThrottle
Sourcepub fn new(config: AutoThrottleConfig) -> Self
pub fn new(config: AutoThrottleConfig) -> Self
Create a new auto-throttle with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration.
Sourcepub fn record_latency(&self, domain: &str, latency: Duration)
pub fn record_latency(&self, domain: &str, latency: Duration)
Record a response latency for a domain.
Call this after each successful (or failed) fetch with the elapsed wall-clock time. The EMA is updated atomically.
Sourcepub fn delay_for(&self, domain: &str) -> Duration
pub fn delay_for(&self, domain: &str) -> Duration
Compute the adaptive delay for a domain.
Formula: delay = ema_latency / target_concurrency, clamped to
[min_delay_ms, max_delay_ms].
Returns Duration::ZERO if no samples have been recorded yet
(cold-start: don’t delay until we have data).
Sourcepub fn latency_ms(&self, domain: &str) -> Option<f64>
pub fn latency_ms(&self, domain: &str) -> Option<f64>
Get the current EMA latency for a domain in milliseconds.
Returns None if no samples recorded.
Auto Trait Implementations§
impl !Freeze for AutoThrottle
impl !RefUnwindSafe for AutoThrottle
impl Send for AutoThrottle
impl Sync for AutoThrottle
impl Unpin for AutoThrottle
impl UnsafeUnpin for AutoThrottle
impl UnwindSafe for AutoThrottle
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
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>
Converts
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>
Converts
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