pub struct AdaptiveThrottler { /* private fields */ }Expand description
Implements a probabilistic throttler based on observed failure rates.
This is an implementation of the Adaptive Throttling strategy described in Site Reliability Engineering book. The basic idea is to stochastically reject some of the retry attempts, with a rejection probability that increases as the number of failures increases, and decreases with the number of successful requests.
The rejection rate probability is defined by:
threshold = (requests - factor * accepts) / (requests + 1)
rejection_probability = max(0, threshold)Where requests is the number of requests completed, and accepts is the
number of requests accepted by the service, including requests that fail due
to parameter validation, authorization checks, or any non-transient
failures.
Note that accepts <= requests but the threshold value might be negative
as factor can be higher than 1.0. In fact, the SRE book recommends using
2.0 as the initial factor.
Setting factor to lower values makes the algorithm reject retry attempts
with higher probability. For example, setting it to zero would reject some
retry attempts even if all requests have succeeded. Setting factor to
higher values allows more retry attempts.
Implementations§
Source§impl AdaptiveThrottler
impl AdaptiveThrottler
Sourcepub fn new(factor: f64) -> Result<Self>
pub fn new(factor: f64) -> Result<Self>
Creates a new adaptive throttler with the given factor.
§Parameters
factor- a factor to adjust the relative weight of transient failures vs. accepted requests. See the struct definition for details.
§Example
fn configure_throttler() -> Result<http_client::ClientConfig> {
let throttler = AdaptiveThrottler::new(2.0)?;
Ok(http_client::ClientConfig::default()
.set_retry_throttler(throttler))
}Sourcepub fn clamp(factor: f64) -> Self
pub fn clamp(factor: f64) -> Self
Creates a new adaptive throttler clamping factor to a valid range.
§Parameters
factor- a factor to adjust the relative weight of transient failures vs. accepted requests. See the struct definition for details. Clamped to zero if the value is negative.
§Example
fn configure_throttler() -> options::ClientConfig {
let throttler = AdaptiveThrottler::clamp(2.0);
options::ClientConfig::default()
.set_retry_throttler(throttler)
}Trait Implementations§
Source§impl Clone for AdaptiveThrottler
impl Clone for AdaptiveThrottler
Source§fn clone(&self) -> AdaptiveThrottler
fn clone(&self) -> AdaptiveThrottler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AdaptiveThrottler
impl Debug for AdaptiveThrottler
Source§impl Default for AdaptiveThrottler
impl Default for AdaptiveThrottler
Source§impl RetryThrottler for AdaptiveThrottler
impl RetryThrottler for AdaptiveThrottler
Source§fn throttle_retry_attempt(&self) -> bool
fn throttle_retry_attempt(&self) -> bool
true
if the request should be throttled. Read more