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§
- Batch
Config - Configuration for
PeerMessageBatcher. - Batch
Flush - A completed batch ready for delivery.
- Batch
Message - A single outbound message queued for batched delivery.
- Batcher
Stats - Aggregate statistics for a
PeerMessageBatcher. - Peer
Message Batcher - Batches outbound messages per-peer and flushes them when thresholds are met.
Enums§
- Flush
Reason - Reason why a batch was flushed.