d_engine_client/config.rs
1use std::time::Duration;
2
3use crate::utils::get_now_as_u32;
4
5/// Client configuration parameters for network connection management
6///
7/// Encapsulates all tunable settings for establishing and maintaining
8/// network connections, including timeouts, keepalive policies,
9/// and performance-related options.
10///
11/// # Key Configuration Areas
12/// - Connection establishment (TCP handshake timeout)
13/// - Request/response lifecycle control
14/// - HTTP/2 protocol optimization
15/// - Network efficiency settings (compression, frame sizing)
16#[derive(Debug, Clone)]
17pub struct ClientConfig {
18 /// Client id representation
19 pub id: u32,
20
21 /// Maximum time to wait for establishing a TCP connection
22 /// Default: 1 second
23 pub connect_timeout: Duration,
24
25 /// Maximum time to wait for a complete RPC response
26 /// Default: 3 seconds
27 pub request_timeout: Duration,
28
29 /// TCP keepalive duration for idle connections
30 /// Default: 5 minutes (300s)
31 pub tcp_keepalive: Duration,
32
33 /// Interval for HTTP/2 keepalive pings
34 /// Default: 1 minute (60s)
35 pub http2_keepalive_interval: Duration,
36
37 /// Timeout for HTTP/2 keepalive pings
38 /// Default: 20 seconds
39 pub http2_keepalive_timeout: Duration,
40
41 /// Maximum size of a single HTTP/2 frame in bytes
42 /// Recommended: 1MB (1048576) to 16MB (16777215)
43 /// Default: 1MB
44 pub max_frame_size: u32,
45
46 /// Enable Gzip compression for network traffic
47 /// Tradeoff: Reduces bandwidth usage at the cost of CPU
48 /// Default: true (enabled)
49 pub enable_compression: bool,
50
51 /// Maximum time to wait for the cluster to elect a leader during build() or refresh().
52 /// Controls how long the client waits for noop-committed leader readiness.
53 /// Caller-controlled: set shorter for health checks, longer for production startup.
54 /// Default: 5 seconds
55 pub cluster_ready_timeout: Duration,
56}
57
58impl Default for ClientConfig {
59 fn default() -> Self {
60 Self {
61 id: get_now_as_u32(),
62 connect_timeout: Duration::from_millis(1000),
63 request_timeout: Duration::from_millis(3000),
64 tcp_keepalive: Duration::from_secs(300),
65 http2_keepalive_interval: Duration::from_secs(60),
66 http2_keepalive_timeout: Duration::from_secs(20),
67 max_frame_size: 1 << 20, // 1MB
68 enable_compression: false,
69 cluster_ready_timeout: Duration::from_secs(5),
70 }
71 }
72}