pub struct AdaptiveBatcher { /* private fields */ }Expand description
Adaptive batch sizing based on queue pressure and latency.
This batcher dynamically adjusts batch size to optimize throughput:
- Burst mode: When queue depth > 100, uses maximum batch size
- Latency pressure: When latency exceeds target, reduces batch size
- Normal mode: Gradually grows toward maximum batch size
§Performance
Adaptive batching can improve throughput by 15-30% for bursty workloads by amortizing per-packet overhead while maintaining latency SLOs.
Implementations§
Source§impl AdaptiveBatcher
impl AdaptiveBatcher
Sourcepub fn with_config(
min_batch_size: usize,
max_batch_size: usize,
target_latency_us: u64,
) -> Self
pub fn with_config( min_batch_size: usize, max_batch_size: usize, target_latency_us: u64, ) -> Self
Create a new adaptive batcher with custom configuration.
Sourcepub fn optimal_size(&self) -> usize
pub fn optimal_size(&self) -> usize
Get the optimal batch size based on current conditions.
This method is called before building a batch to determine how much data to accumulate before sending.
Sourcepub fn record(&self, batch_size: usize, latency_us: u64, queue_depth: usize)
pub fn record(&self, batch_size: usize, latency_us: u64, queue_depth: usize)
Record metrics after sending a batch.
This updates the internal state used by optimal_size().
§Arguments
batch_size- Size of the batch in byteslatency_us- Time taken to send the batch in microsecondsqueue_depth- Current pending queue depth
Sourcepub fn min_batch_size(&self) -> usize
pub fn min_batch_size(&self) -> usize
Get the minimum batch size.
Sourcepub fn max_batch_size(&self) -> usize
pub fn max_batch_size(&self) -> usize
Get the maximum batch size.
Sourcepub fn target_latency_us(&self) -> u64
pub fn target_latency_us(&self) -> u64
Get the target latency in microseconds.
Sourcepub fn avg_latency_us(&self) -> u64
pub fn avg_latency_us(&self) -> u64
Get the current average batch latency in microseconds.
Sourcepub fn current_queue_depth(&self) -> usize
pub fn current_queue_depth(&self) -> usize
Get the current queue depth.
Sourcepub fn is_burst_mode(&self) -> bool
pub fn is_burst_mode(&self) -> bool
Check if burst mode is active.
Sourcepub fn total_batches(&self) -> u64
pub fn total_batches(&self) -> u64
Get the total number of batches processed.
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Get the total bytes sent.
Sourcepub fn avg_batch_size(&self) -> usize
pub fn avg_batch_size(&self) -> usize
Get the average batch size.
Sourcepub fn reset_metrics(&self)
pub fn reset_metrics(&self)
Reset all metrics.