pub struct AdaptiveTimeout { /* private fields */ }Expand description
Computes adaptive timeouts based on observed latency quantiles.
For each destination, queries the tracker for a high quantile (default: P99.99), applies a safety factor and exponential backoff, clamps between floor and ceiling, and takes the maximum across all destinations.
Falls back to pure exponential backoff when histogram data is insufficient.
§Example
use std::time::{Duration, Instant};
use adaptive_timeout::{AdaptiveTimeout, LatencyTracker};
let now = Instant::now();
let mut tracker = LatencyTracker::<u32, Instant>::default();
let timeout = AdaptiveTimeout::default();
// No data yet — falls back to exponential backoff (min_timeout).
let t = timeout.select_timeout(&mut tracker, &[1u32], 1, now);
assert_eq!(t, Duration::from_millis(250));Implementations§
Source§impl AdaptiveTimeout
impl AdaptiveTimeout
Sourcepub fn new(config: TimeoutConfig) -> Self
pub fn new(config: TimeoutConfig) -> Self
Creates a new AdaptiveTimeout with the given configuration.
Sourcepub fn select_timeout<'a, D, I, H, const N: usize>(
&self,
tracker: &mut LatencyTracker<D, I, H, N>,
destinations: impl IntoIterator<Item = &'a D>,
attempt: u32,
now: I,
) -> Duration
pub fn select_timeout<'a, D, I, H, const N: usize>( &self, tracker: &mut LatencyTracker<D, I, H, N>, destinations: impl IntoIterator<Item = &'a D>, attempt: u32, now: I, ) -> Duration
Computes an adaptive timeout for a request to the given destinations.
Returns the maximum timeout across all destinations, clamped to
[min_timeout, max_timeout]. attempt is 1-based; higher attempts
produce longer timeouts via exponential backoff.
Sourcepub fn select_timeout_ms<'a, D, I, H, const N: usize>(
&self,
tracker: &mut LatencyTracker<D, I, H, N>,
destinations: impl IntoIterator<Item = &'a D>,
attempt: u32,
now: I,
) -> u64
pub fn select_timeout_ms<'a, D, I, H, const N: usize>( &self, tracker: &mut LatencyTracker<D, I, H, N>, destinations: impl IntoIterator<Item = &'a D>, attempt: u32, now: I, ) -> u64
Computes an adaptive timeout in milliseconds.
See select_timeout.
Sourcepub fn exponential_backoff(&self, attempt: u32) -> Duration
pub fn exponential_backoff(&self, attempt: u32) -> Duration
Pure exponential backoff: min_timeout * 2^(attempt - 1), clamped to
max_timeout. Fallback when histogram data is insufficient.
Sourcepub fn exponential_backoff_ms(&self, attempt: u32) -> u64
pub fn exponential_backoff_ms(&self, attempt: u32) -> u64
Pure exponential backoff in milliseconds.
Sourcepub fn config(&self) -> &TimeoutConfig
pub fn config(&self) -> &TimeoutConfig
Returns a reference to the timeout configuration.
Trait Implementations§
Source§impl Clone for AdaptiveTimeout
impl Clone for AdaptiveTimeout
Source§fn clone(&self) -> AdaptiveTimeout
fn clone(&self) -> AdaptiveTimeout
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more