pub struct RequestDeduplicator {
pub max_waiters_per_key: usize,
pub request_timeout: Duration,
pub stats: DedupStats,
/* private fields */
}Expand description
Deduplicates concurrent requests for the same CID.
try_acquire returns Leader to the first caller; all subsequent callers
for the same CID before resolve is called receive a Waiter handle.
Once the leader calls resolve, the flight record is marked complete and
removed, so the next caller starts a fresh leader/waiter cycle.
If the waiter queue reaches max_waiters_per_key, additional callers are
promoted to Leader so they can independently issue their own request.
Fields§
§max_waiters_per_key: usizeMaximum number of waiters allowed per CID before overflow callers become leaders.
request_timeout: DurationDuration after which unresolved flight records are considered stale.
stats: DedupStatsAtomic counters.
Implementations§
Source§impl RequestDeduplicator
impl RequestDeduplicator
Sourcepub fn new(max_waiters_per_key: usize, request_timeout: Duration) -> Self
pub fn new(max_waiters_per_key: usize, request_timeout: Duration) -> Self
Creates a new deduplicator with the given waiter cap and request timeout.
§Arguments
max_waiters_per_key– once this many waiters exist for a CID, additional callers are promoted toLeaderinstead of waiting.request_timeout– flights older than this are pruned bytimeout_expired_flights.
Sourcepub fn try_acquire(&self, cid: &str) -> AcquireResult
pub fn try_acquire(&self, cid: &str) -> AcquireResult
Attempt to acquire the right to issue the outbound request for cid.
Returns Leader if no in-flight record exists (or the waiter queue is
full), or Waiter(handle) if the caller should coalesce.
Sourcepub fn resolve(&self, cid: &str, result: ResolveResult) -> bool
pub fn resolve(&self, cid: &str, result: ResolveResult) -> bool
Mark the in-flight record for cid as resolved with result.
The flight record is removed from in_flight; the number of waiters
that were coalesced is added to DedupStats::total_coalesced.
Returns true if an active flight was found and resolved, false if
no matching record existed.
Sourcepub fn timeout_expired_flights(&self) -> usize
pub fn timeout_expired_flights(&self) -> usize
Prune all flight records that have exceeded request_timeout.
Returns the number of records removed.
Sourcepub fn in_flight_count(&self) -> usize
pub fn in_flight_count(&self) -> usize
Returns the number of currently in-flight records.
Sourcepub fn waiter_count_for(&self, cid: &str) -> Option<usize>
pub fn waiter_count_for(&self, cid: &str) -> Option<usize>
Returns the current waiter count for a specific CID, or None if no
in-flight record exists for that CID.
Trait Implementations§
Source§impl Debug for RequestDeduplicator
impl Debug for RequestDeduplicator
Auto Trait Implementations§
impl !Freeze for RequestDeduplicator
impl RefUnwindSafe for RequestDeduplicator
impl Send for RequestDeduplicator
impl Sync for RequestDeduplicator
impl Unpin for RequestDeduplicator
impl UnsafeUnpin for RequestDeduplicator
impl UnwindSafe for RequestDeduplicator
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
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>
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>
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