Skip to main content

Crate adaptive_timeout

Crate adaptive_timeout 

Source
Expand description

Adaptive timeout computation based on observed latency quantiles.

A LatencyTracker records latencies per destination using sliding-window histograms. An AdaptiveTimeout queries the tracker for a high quantile, applies a safety factor and exponential backoff, and clamps the result between a configurable floor and ceiling.

When insufficient data is available, falls back to pure exponential backoff.

§Per-service tracking

Create one LatencyTracker per service/operation type. This keeps each service’s latency distribution independent.

§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.
let t = timeout.select_timeout(&mut tracker, &[1u32], 1, now);
assert_eq!(t, Duration::from_millis(250));

// Record some latency observations.
for _ in 0..100 {
    tracker.record_latency(&1u32, Duration::from_millis(50), now);
}

// Now the timeout adapts to observed latencies.
let t = timeout.select_timeout(&mut tracker, &[1u32], 1, now);
assert!(t >= Duration::from_millis(50), "timeout should reflect observed latency");

Re-exports§

pub use clock::Instant;

Modules§

clock

Structs§

AdaptiveTimeout
Computes adaptive timeouts based on observed latency quantiles.
BackoffInterval
Timeout floor and ceiling parsed from a duration-range string.
LatencyTracker
Tracks latencies per destination and provides quantile estimates.
TimeoutConfig
Configuration for AdaptiveTimeout.
TrackerConfig
Configuration for LatencyTracker.

Enums§

ParseError
Errors that can occur when parsing a BackoffInterval string.

Constants§

DEFAULT_SUB_WINDOWS
Default number of sub-windows for the sliding window histogram.

Type Aliases§

MillisNonZero
Milliseconds stored as a NonZeroU32.