Skip to main content

SyncLatencyTracker

Struct SyncLatencyTracker 

Source
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:

§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>
where D: Hash + Eq + Clone + Send + Sync, I: Instant, H: BuildHasher + Default + Clone,

Source

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>
where D: Hash + Eq + Clone + Send + Sync, I: Instant, H: BuildHasher + Clone,

Source

pub fn with_hasher_and_config(hasher: H, config: TrackerConfig) -> Self

Source

pub fn record_latency_from(&self, dest: &D, earlier: I, now: I) -> Duration

Records a latency sample given two instants. Returns the computed duration.

Source

pub fn record_latency(&self, dest: &D, latency: Duration, now: I)

Records a latency sample as a Duration.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self)

Clears all tracked state.

Source

pub fn config(&self) -> &TrackerConfig

Returns a reference to the tracker configuration.

Trait Implementations§

Source§

impl<D, I> Default for SyncLatencyTracker<D, I, RandomState, DEFAULT_SUB_WINDOWS>
where D: Hash + Eq + Clone + Send + Sync, I: Instant,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D, I, H, const N: usize> Freeze for SyncLatencyTracker<D, I, H, N>
where H: Freeze,

§

impl<D, I = Instant, H = RandomState, const N: usize = DEFAULT_SUB_WINDOWS> !RefUnwindSafe for SyncLatencyTracker<D, I, H, N>

§

impl<D, I, H, const N: usize> Send for SyncLatencyTracker<D, I, H, N>
where H: Send, D: Send, I: Send,

§

impl<D, I, H, const N: usize> Sync for SyncLatencyTracker<D, I, H, N>
where H: Sync, D: Send + Sync, I: Send + Sync,

§

impl<D, I, H, const N: usize> Unpin for SyncLatencyTracker<D, I, H, N>
where H: Unpin,

§

impl<D, I, H, const N: usize> UnsafeUnpin for SyncLatencyTracker<D, I, H, N>
where H: UnsafeUnpin,

§

impl<D, I, H, const N: usize> UnwindSafe for SyncLatencyTracker<D, I, H, N>
where H: UnwindSafe, D: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.