pub struct PeerLatencyTracker { /* private fields */ }Expand description
Tracks per-peer latency with sliding windows and enables peer ranking.
This is complementary to AdaptiveLookupScheduler: the scheduler decides
how many concurrent requests to send, while PeerLatencyTracker decides
which peers to prefer.
Implementations§
Source§impl PeerLatencyTracker
impl PeerLatencyTracker
Sourcepub fn record(&mut self, peer_id: &str, latency: Duration)
pub fn record(&mut self, peer_id: &str, latency: Duration)
Record a latency sample for peer_id.
Sourcepub fn p90_for_peer(&self, peer_id: &str) -> Option<Duration>
pub fn p90_for_peer(&self, peer_id: &str) -> Option<Duration>
Return the p90 latency for a specific peer, or None if unknown.
Sourcepub fn fastest_peers(&self, n: usize) -> Vec<String>
pub fn fastest_peers(&self, n: usize) -> Vec<String>
Return the n peer IDs with the lowest median latency.
Peers with no recorded samples are excluded. If fewer than n peers
have samples, all qualifying peers are returned.
Sourcepub fn prune_stale(&mut self, max_age: Duration)
pub fn prune_stale(&mut self, max_age: Duration)
Remove peers whose most recent sample is older than max_age.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Number of peers currently tracked.
Trait Implementations§
Source§impl Debug for PeerLatencyTracker
impl Debug for PeerLatencyTracker
Auto Trait Implementations§
impl Freeze for PeerLatencyTracker
impl RefUnwindSafe for PeerLatencyTracker
impl Send for PeerLatencyTracker
impl Sync for PeerLatencyTracker
impl Unpin for PeerLatencyTracker
impl UnsafeUnpin for PeerLatencyTracker
impl UnwindSafe for PeerLatencyTracker
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more