Skip to main content

BackpressureTracker

Struct BackpressureTracker 

Source
pub struct BackpressureTracker { /* private fields */ }
Expand description

Per-peer receiver-side back-pressure state.

Sibling field on PeerState per bb-runtime/src/framework/peer_state.rs. The tracker is receiver-state-only; sender-side back-off lives in the existing BackoffTable.

Implementations§

Source§

impl BackpressureTracker

Source

pub fn new() -> Self

Construct a fresh tracker with the spec’s defaults (high-water = 75%, K = 3, min-notice-interval = 1 second).

Source

pub fn with_config( high_water_mark_pct: u8, notice_threshold_k: u32, min_notice_interval_ns: u64, ) -> Self

Construct a tracker with custom config values. high_water_mark_pct is clamped to 1..=100; notice_threshold_k is clamped to at least 1; min_notice_interval_ns is clamped to at least 1.

Source

pub fn high_water_mark_pct(&self) -> u8

High-water mark threshold as a percentage.

Source

pub fn is_over_high_water(&self, len: usize, capacity: usize) -> bool

Whether the supplied queue depth (len) crosses the configured high-water mark for the supplied capacity.

Source

pub fn notice_threshold_k(&self) -> u32

K threshold (notices-without-recovery before silent-drop).

Source

pub fn min_notice_interval_ns(&self) -> u64

Minimum interval enforced between successive notices to the same peer.

Source

pub fn is_silent_drop_active(&self, peer: PeerId) -> bool

Whether the peer is currently in silent-drop mode.

Source

pub fn entry(&self, peer: PeerId) -> Option<BackpressureEntry>

Inspect the recorded entry for peer. Returns None when no overload event has been observed for this peer yet.

Source

pub fn iter(&self) -> impl Iterator<Item = (PeerId, BackpressureEntry)> + '_

Iterate (PeerId, BackpressureEntry) for snapshot capture.

Source

pub fn len(&self) -> usize

Number of peers currently tracked.

Source

pub fn is_empty(&self) -> bool

Whether any peer has been tracked.

Source

pub fn observe_overload( &mut self, peer: PeerId, cause: BackoffCause, min_backoff_ns: u64, now_ns: u64, ) -> Decision

Observe an overload condition for peer at now_ns.

Returns:

  • Decision::SilentDrop if the peer is already in silent-drop mode. The caller drops the envelope; no notice is emitted.
  • Decision::Suppress if a recent notice’s quoted back-off window has not yet elapsed (duplicate suppression).
  • Decision::EmitNotice if the caller should emit a notice. The tracker increments notices_sent + records the emission timestamp + back-off. If this push crosses the K threshold, the entry transitions to silent_drop_active in the next observation - the current decision still emits the K-th notice so the sender gets the final warning before silent drop kicks in.

min_backoff_ns is the back-off duration the caller intends to quote on the notice. The tracker uses it for the duplicate-suppression window. A 0 value collapses to the configured min_notice_interval_ns floor.

Source

pub fn record_recovery(&mut self, peer: PeerId)

Record that the sender has recovered (e.g., φ-accrual transitioned back to Live). Resets the per-peer counter and clears silent_drop_active. The next observe_overload for the peer starts fresh.

Source

pub fn in_suppression_window(&self, peer: PeerId, now_ns: u64) -> bool

Whether peer is currently inside its duplicate-suppression window. Used by tests + introspection.

Trait Implementations§

Source§

impl Default for BackpressureTracker

Source§

fn default() -> Self

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

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedComponent for T
where T: Any + Send + Sync,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more