use std::time::Duration;
#[derive(Debug, Clone, PartialEq)]
pub struct BatchConfig {
pub max_rows: usize,
pub max_wait: Duration,
pub initial_buffer_size: usize,
pub max_buffer_size: usize,
pub buffer_shrink_threshold: usize,
pub max_retries: u32,
pub retry_base_delay: Duration,
pub channel_capacity: usize,
}
impl Default for BatchConfig {
fn default() -> Self {
Self {
max_rows: 50_000,
max_wait: Duration::from_secs(5),
initial_buffer_size: 1024 * 1024, max_buffer_size: 64 * 1024 * 1024, buffer_shrink_threshold: 2 * 1024 * 1024, max_retries: 3,
retry_base_delay: Duration::from_millis(100),
channel_capacity: 10_000,
}
}
}
impl BatchConfig {
pub fn high_throughput() -> Self {
Self {
max_rows: 100_000,
max_wait: Duration::from_secs(10),
initial_buffer_size: 4 * 1024 * 1024, max_buffer_size: 256 * 1024 * 1024, buffer_shrink_threshold: 8 * 1024 * 1024, channel_capacity: 100_000,
..Default::default()
}
}
pub fn low_latency() -> Self {
Self {
max_rows: 1_000,
max_wait: Duration::from_millis(100),
initial_buffer_size: 64 * 1024, max_buffer_size: 16 * 1024 * 1024, buffer_shrink_threshold: 128 * 1024, channel_capacity: 1_000,
..Default::default()
}
}
}
#[derive(Debug, Clone)]
pub struct FlushStats {
pub rows_flushed: usize,
pub bytes_sent: usize,
pub duration: Duration,
pub batch_age: Duration,
}