clicktype_batch/
config.rs1use std::time::Duration;
4
5#[derive(Debug, Clone, PartialEq)]
7pub struct BatchConfig {
8 pub max_rows: usize,
10
11 pub max_wait: Duration,
13
14 pub initial_buffer_size: usize,
16
17 pub max_buffer_size: usize,
19
20 pub buffer_shrink_threshold: usize,
24
25 pub max_retries: u32,
27
28 pub retry_base_delay: Duration,
30
31 pub channel_capacity: usize,
33}
34
35impl Default for BatchConfig {
36 fn default() -> Self {
37 Self {
38 max_rows: 50_000,
39 max_wait: Duration::from_secs(5),
40 initial_buffer_size: 1024 * 1024, max_buffer_size: 64 * 1024 * 1024, buffer_shrink_threshold: 2 * 1024 * 1024, max_retries: 3,
44 retry_base_delay: Duration::from_millis(100),
45 channel_capacity: 10_000,
46 }
47 }
48}
49
50impl BatchConfig {
51 pub fn high_throughput() -> Self {
53 Self {
54 max_rows: 100_000,
55 max_wait: Duration::from_secs(10),
56 initial_buffer_size: 4 * 1024 * 1024, max_buffer_size: 256 * 1024 * 1024, buffer_shrink_threshold: 8 * 1024 * 1024, channel_capacity: 100_000,
60 ..Default::default()
61 }
62 }
63
64 pub fn low_latency() -> Self {
66 Self {
67 max_rows: 1_000,
68 max_wait: Duration::from_millis(100),
69 initial_buffer_size: 64 * 1024, max_buffer_size: 16 * 1024 * 1024, buffer_shrink_threshold: 128 * 1024, channel_capacity: 1_000,
73 ..Default::default()
74 }
75 }
76}
77
78#[derive(Debug, Clone)]
80pub struct FlushStats {
81 pub rows_flushed: usize,
83
84 pub bytes_sent: usize,
86
87 pub duration: Duration,
89
90 pub batch_age: Duration,
92}