Skip to main content

Module message_batcher

Module message_batcher 

Source
Expand description

Peer message batching for outbound message coalescing

This module provides PeerMessageBatcher, which accumulates outbound messages destined for the same peer and flushes them as a single batch when a size or time threshold is reached.

§Design

Messages are accumulated per-peer in an in-memory queue. Flushing is triggered by:

  • Size threshold: accumulated payload bytes >= max_batch_bytes
  • Count threshold: number of queued messages >= max_batch_count
  • Age threshold: oldest message age (in ticks) >= max_age_ticks
  • Manual flush: caller explicitly flushes a peer or all peers

The batcher uses a logical tick counter (u64) rather than wall-clock time, allowing deterministic testing without OS time dependencies.

Structs§

BatchConfig
Configuration for PeerMessageBatcher.
BatchFlush
A completed batch ready for delivery.
BatchMessage
A single outbound message queued for batched delivery.
BatcherStats
Aggregate statistics for a PeerMessageBatcher.
PeerMessageBatcher
Batches outbound messages per-peer and flushes them when thresholds are met.

Enums§

FlushReason
Reason why a batch was flushed.