pub struct SyncLatencyTracker<D, I: Instant = Instant, H = RandomState, const N: usize = DEFAULT_SUB_WINDOWS> { /* private fields */ }Expand description
Thread-safe latency tracker backed by DashMap.
Drop-in concurrent replacement for LatencyTracker.
All methods take &self instead of &mut self, and the type is both
Send and Sync.
§Type parameters
Same as LatencyTracker:
D— destination key.I— time source (defaults tostd::time::Instant).N— number of sub-windows (defaults toDEFAULT_SUB_WINDOWS).
§Example
use std::time::Instant;
use adaptive_timeout::SyncLatencyTracker;
let now = Instant::now();
let tracker = SyncLatencyTracker::<u32>::default();
// Can be called from any thread via &tracker.
tracker.record_latency_ms(&1u32, 50, now);
let p99 = tracker.quantile_ms(&1u32, 0.99, now);Implementations§
Source§impl<D, I, H, const N: usize> SyncLatencyTracker<D, I, H, N>
impl<D, I, H, const N: usize> SyncLatencyTracker<D, I, H, N>
Sourcepub fn new(config: TrackerConfig) -> Self
pub fn new(config: TrackerConfig) -> Self
Creates a new tracker with the given configuration.
Source§impl<D, I, H, const N: usize> SyncLatencyTracker<D, I, H, N>
impl<D, I, H, const N: usize> SyncLatencyTracker<D, I, H, N>
pub fn with_hasher_and_config(hasher: H, config: TrackerConfig) -> Self
Sourcepub fn record_latency_from(&self, dest: &D, earlier: I, now: I) -> Duration
pub fn record_latency_from(&self, dest: &D, earlier: I, now: I) -> Duration
Records a latency sample given two instants. Returns the computed duration.
Sourcepub fn record_latency(&self, dest: &D, latency: Duration, now: I)
pub fn record_latency(&self, dest: &D, latency: Duration, now: I)
Records a latency sample as a Duration.
Sourcepub fn record_latency_ms(&self, dest: &D, latency_ms: u64, now: I)
pub fn record_latency_ms(&self, dest: &D, latency_ms: u64, now: I)
Records a latency sample in milliseconds.
Takes &self — safe to call from multiple threads concurrently.
Operations on different destinations proceed in parallel; operations
on the same destination serialize briefly.
Sourcepub fn quantile_ms(&self, dest: &D, quantile: f64, now: I) -> Option<u64>
pub fn quantile_ms(&self, dest: &D, quantile: f64, now: I) -> Option<u64>
Returns the estimated latency in milliseconds at the given quantile,
or None if insufficient data.
Takes &self — safe to call from multiple threads concurrently.
Sourcepub fn quantile(&self, dest: &D, quantile: f64, now: I) -> Option<Duration>
pub fn quantile(&self, dest: &D, quantile: f64, now: I) -> Option<Duration>
Returns the estimated latency as a Duration at the given quantile,
or None if insufficient data.
Sourcepub fn config(&self) -> &TrackerConfig
pub fn config(&self) -> &TrackerConfig
Returns a reference to the tracker configuration.