d_engine/client/
config.rs

1use std::time::Duration;
2
3use crate::time::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
52impl Default for ClientConfig {
53    fn default() -> Self {
54        Self {
55            id: get_now_as_u32(),
56            connect_timeout: Duration::from_millis(1000),
57            request_timeout: Duration::from_millis(3000),
58            tcp_keepalive: Duration::from_secs(300),
59            http2_keepalive_interval: Duration::from_secs(60),
60            http2_keepalive_timeout: Duration::from_secs(20),
61            max_frame_size: 1 << 20, // 1MB
62            enable_compression: true,
63        }
64    }
65}