Skip to main content

BatchMetrics

Struct BatchMetrics 

Source
pub struct BatchMetrics {
    pub batches_dispatched: u64,
    pub items_processed: u64,
    pub items_submitted: u64,
    pub items_rejected: u64,
    pub items_timed_out: u64,
    pub total_processing_ns: u64,
    pub total_formation_ns: u64,
    pub min_batch_size: u64,
    pub max_batch_size_seen: u64,
    pub configured_max_batch_size: u64,
    pub consecutive_errors: u64,
}
Expand description

Live metrics snapshot for a batch coordinator.

All counters are monotonically increasing. Compute rates by taking deltas between snapshots.

§Counter semantics

  • items_submitted — incremented when a feed thread calls submit_and_wait, before the channel send. Every call increments this exactly once, regardless of outcome.
  • items_rejected — incremented when try_send fails (QueueFull or Disconnected). Rejected items never reach the coordinator.
  • items_processed — incremented by the coordinator after the batch processor returns (success or error). Each item in the dispatched batch is counted.

Invariant (approximate under concurrent reads): items_submitted >= items_processed + items_rejected.

Fields§

§batches_dispatched: u64

Total batches dispatched to the processor.

§items_processed: u64

Total items successfully dispatched and processed (success or error) by the batch processor. Does not include rejected items.

§items_submitted: u64

Total items submitted by feed threads (includes both accepted and rejected submissions).

§items_rejected: u64

Items rejected because the submission queue was full or the coordinator was shut down (Disconnected). These items never reached the coordinator thread.

§items_timed_out: u64

Items whose response was not received before the feed-side safety timeout (max_latency + response_timeout). The coordinator may still process these items, but the feed thread abandoned waiting.

A non-zero value indicates the batch processor is slower than the configured safety margin allows. Consider increasing response_timeout or reducing max_batch_size.

§total_processing_ns: u64

Cumulative batch processing time (nanoseconds).

§total_formation_ns: u64

Cumulative batch formation wait time (nanoseconds).

§min_batch_size: u64

Smallest batch size dispatched (0 if no batches yet).

§max_batch_size_seen: u64

Largest batch size dispatched.

§configured_max_batch_size: u64

The configured max_batch_size for this coordinator.

Included in the snapshot so callers can compute fill ratios without retaining a reference to the original config.

§consecutive_errors: u64

Number of consecutive batch errors (processor Err or panic) since the last successful dispatch. Reset to 0 on success.

Useful for alerting: a steadily increasing value indicates a persistently broken processor. Zero means the last batch succeeded.

Implementations§

Source§

impl BatchMetrics

Source

pub fn pending_items(&self) -> u64

Approximate number of items currently in-flight (submitted but not yet processed or rejected).

Computed from atomic counters — may be briefly inconsistent under heavy contention, but sufficient for monitoring and dashboards.

Caveat: items that timed out on the feed side may still be processed by the coordinator. When this happens, items_processed includes the timed-out item and this counter can undercount. The discrepancy is bounded by items_timed_out.

Source

pub fn rejection_rate(&self) -> Option<f64>

Fraction of submissions rejected (items_rejected / items_submitted).

Returns None if no items have been submitted. A consistently non-zero value indicates sustained overload.

Source

pub fn timeout_rate(&self) -> Option<f64>

Fraction of submissions that timed out (items_timed_out / items_submitted).

Returns None if no items have been submitted. A non-zero value indicates the processor is too slow for the configured safety timeout.

Source

pub fn avg_batch_size(&self) -> Option<f64>

Average batch size across all dispatched batches.

Returns None if no batches have been dispatched yet. O(1), zero-allocation.

Source

pub fn avg_fill_ratio(&self) -> Option<f64>

Average batch fill ratio: avg_batch_size / configured_max_batch_size.

A value of 1.0 means batches are consistently full. Lower values indicate partial batches (dispatched on timeout rather than on size).

Returns None if no batches have been dispatched yet. O(1), zero-allocation.

Source

pub fn avg_processing_ns(&self) -> Option<f64>

Average processing time per batch (nanoseconds).

Returns None if no batches have been dispatched yet. O(1), zero-allocation.

Source

pub fn avg_formation_ns(&self) -> Option<f64>

Average formation wait time per batch (nanoseconds).

Formation time is the interval from the first item arriving to the batch being dispatched. Lower values indicate faster batch filling (high submission rate or small batch size).

Returns None if no batches have been dispatched yet. O(1), zero-allocation.

Trait Implementations§

Source§

impl Clone for BatchMetrics

Source§

fn clone(&self) -> BatchMetrics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BatchMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BatchMetrics

Source§

fn default() -> BatchMetrics

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

impl Display for BatchMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Human-readable diagnostic summary.

Example output:

batches=120 items=480/500 rejected=15 timed_out=2 fill=0.80 \
avg_proc=12.5ms avg_form=8.2ms consec_err=0
Source§

impl Copy for BatchMetrics

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<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