1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! 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
//!
//! ```rust
//! 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");
//! ```
pub use Instant;
pub use ;
pub use ;
pub use SyncLatencyTracker;
pub use AdaptiveTimeout;
pub use DEFAULT_SUB_WINDOWS;
pub use LatencyTracker;