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.
§Example
let throttler = AdaptiveThrottler::new(2.0)?;Implementations§
Source§impl AdaptiveThrottler
impl AdaptiveThrottler
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
let throttler = AdaptiveThrottler::clamp(2.0);Trait Implementations§
Source§impl Clone for AdaptiveThrottler
impl Clone for AdaptiveThrottler
Source§fn clone(&self) -> AdaptiveThrottler
fn clone(&self) -> AdaptiveThrottler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more