pub struct AdaptiveRateLimiter { /* private fields */ }Available on crate feature
resilience only.Expand description
Adaptive rate limiter that backs off when receiving external rate limits.
When external services return 429 responses, this limiter reduces its throughput to avoid hammering the service.
Implementations§
Source§impl AdaptiveRateLimiter
impl AdaptiveRateLimiter
Sourcepub fn new(rps: u32, burst_size: u32) -> Self
pub fn new(rps: u32, burst_size: u32) -> Self
Create a new adaptive rate limiter.
§Arguments
rps- Base requests per secondburst_size- Burst capacity
Sourcepub fn with_recovery_interval(self, interval: Duration) -> Self
pub fn with_recovery_interval(self, interval: Duration) -> Self
Set the recovery interval.
Sourcepub fn with_min_rps(self, min_rps: u32) -> Self
pub fn with_min_rps(self, min_rps: u32) -> Self
Set the minimum RPS floor.
Sourcepub fn with_backoff_factor(self, factor: f64) -> Self
pub fn with_backoff_factor(self, factor: f64) -> Self
Set the backoff factor (0.0-1.0).
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful request.
Sourcepub fn record_rate_limit(&self)
pub fn record_rate_limit(&self)
Record a rate limit response from an external service.
Sourcepub fn check(&self) -> Result<(), RateLimitError>
pub fn check(&self) -> Result<(), RateLimitError>
Check if a request is allowed.
Sourcepub fn get_status(&self) -> RateLimiterStatus
pub fn get_status(&self) -> RateLimiterStatus
Get the current status.
Sourcepub fn external_limit_count(&self) -> u64
pub fn external_limit_count(&self) -> u64
Get external rate limit count.
Auto Trait Implementations§
impl !Freeze for AdaptiveRateLimiter
impl !RefUnwindSafe for AdaptiveRateLimiter
impl Send for AdaptiveRateLimiter
impl Sync for AdaptiveRateLimiter
impl Unpin for AdaptiveRateLimiter
impl UnwindSafe for AdaptiveRateLimiter
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 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>
Wrap the input message
T in a tonic::RequestSource§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>
Wrap the input message
T in a tonic::Request