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 callssubmit_and_wait, before the channel send. Every call increments this exactly once, regardless of outcome.items_rejected— incremented whentry_sendfails (QueueFullorDisconnected). 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: u64Total batches dispatched to the processor.
items_processed: u64Total items successfully dispatched and processed (success or error) by the batch processor. Does not include rejected items.
items_submitted: u64Total items submitted by feed threads (includes both accepted and rejected submissions).
items_rejected: u64Items rejected because the submission queue was full or the
coordinator was shut down (Disconnected). These items never
reached the coordinator thread.
items_timed_out: u64Items 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: u64Cumulative batch processing time (nanoseconds).
total_formation_ns: u64Cumulative batch formation wait time (nanoseconds).
min_batch_size: u64Smallest batch size dispatched (0 if no batches yet).
max_batch_size_seen: u64Largest batch size dispatched.
configured_max_batch_size: u64The 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: u64Number 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
impl BatchMetrics
Sourcepub fn pending_items(&self) -> u64
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.
Sourcepub fn rejection_rate(&self) -> Option<f64>
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.
Sourcepub fn timeout_rate(&self) -> Option<f64>
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.
Sourcepub fn avg_batch_size(&self) -> Option<f64>
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.
Sourcepub fn avg_fill_ratio(&self) -> Option<f64>
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.
Sourcepub fn avg_processing_ns(&self) -> Option<f64>
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.
Sourcepub fn avg_formation_ns(&self) -> Option<f64>
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
impl Clone for BatchMetrics
Source§fn clone(&self) -> BatchMetrics
fn clone(&self) -> BatchMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BatchMetrics
impl Debug for BatchMetrics
Source§impl Default for BatchMetrics
impl Default for BatchMetrics
Source§fn default() -> BatchMetrics
fn default() -> BatchMetrics
Source§impl Display for BatchMetrics
impl Display for BatchMetrics
impl Copy for BatchMetrics
Auto Trait Implementations§
impl Freeze for BatchMetrics
impl RefUnwindSafe for BatchMetrics
impl Send for BatchMetrics
impl Sync for BatchMetrics
impl Unpin for BatchMetrics
impl UnsafeUnpin for BatchMetrics
impl UnwindSafe for BatchMetrics
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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