pub struct PeerMessageBatcher {
pub pending: HashMap<String, Vec<BatchMessage>>,
pub config: BatchConfig,
pub stats: BatcherStats,
pub next_id: u64,
pub tick: u64,
}Expand description
Batches outbound messages per-peer and flushes them when thresholds are met.
Fields§
§pending: HashMap<String, Vec<BatchMessage>>Per-peer pending message queues.
config: BatchConfigBatching configuration.
stats: BatcherStatsRunning statistics.
next_id: u64Next message ID to assign.
tick: u64Current logical tick counter.
Implementations§
Source§impl PeerMessageBatcher
impl PeerMessageBatcher
Sourcepub fn new(config: BatchConfig) -> Self
pub fn new(config: BatchConfig) -> Self
Create a new batcher with the supplied configuration.
Sourcepub fn push(&mut self, peer_id: String, payload: Vec<u8>) -> Option<BatchFlush>
pub fn push(&mut self, peer_id: String, payload: Vec<u8>) -> Option<BatchFlush>
Push a message for peer_id.
Assigns a monotonic msg_id and records enqueued_at = tick, then appends
to the peer’s queue. If either the size or count threshold is exceeded
after appending, the peer’s queue is immediately flushed and the resulting
BatchFlush is returned. Otherwise None is returned and the message
stays in the queue until the next flush trigger.
Sourcepub fn tick_advance(&mut self) -> Vec<BatchFlush>
pub fn tick_advance(&mut self) -> Vec<BatchFlush>
Advance the logical tick counter by one and check age thresholds.
For each peer whose oldest pending message has been waiting for at least
max_age_ticks ticks, the queue is flushed with AgeThreshold.
Returns all flushes that were triggered.
Sourcepub fn flush_peer(&mut self, peer_id: &str) -> Option<BatchFlush>
pub fn flush_peer(&mut self, peer_id: &str) -> Option<BatchFlush>
Force-flush a specific peer’s pending messages with ManualFlush.
Returns None if the peer has no pending messages.
Sourcepub fn flush_all(&mut self) -> Vec<BatchFlush>
pub fn flush_all(&mut self) -> Vec<BatchFlush>
Force-flush every peer that has pending messages with ManualFlush.
Sourcepub fn stats(&self) -> &BatcherStats
pub fn stats(&self) -> &BatcherStats
Return a reference to the current statistics.
Auto Trait Implementations§
impl Freeze for PeerMessageBatcher
impl RefUnwindSafe for PeerMessageBatcher
impl Send for PeerMessageBatcher
impl Sync for PeerMessageBatcher
impl Unpin for PeerMessageBatcher
impl UnsafeUnpin for PeerMessageBatcher
impl UnwindSafe for PeerMessageBatcher
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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