Function failsafe::failure_policy::success_rate_over_time_window
source · pub fn success_rate_over_time_window<BACKOFF>(
required_success_rate: f64,
min_request_threshold: u32,
window: Duration,
backoff: BACKOFF,
) -> SuccessRateOverTimeWindow<BACKOFF>
Expand description
Returns a policy based on an exponentially-weighted moving average success rate over a time window. A moving average is used so the success rate calculation is biased towards more recent requests.
If the computed weighted success rate is less than the required success rate,
mark_dead_on_failure
will return Some(Duration)
.
See ema::Ema
for how the success rate is computed.
required_success_rate
- a success rate that must be met.min_request_threshold
- minimum number of requests in the pastwindow
formark_dead_on_failure
to return a duration.window
- window over which the success rate is tracked.mark_dead_on_failure
will return None, until we get requests for a duration of at leastwindow
.backoff
- stream of durations to use for the next duration returned frommark_dead_on_failure
§Panics
When required_success_rate
isn’t in [0.0, 1.0]
interval.