pub struct Config { /* private fields */ }Expand description
Socket configuration for BingerUdp.
Create a Config with Config::new() or Config::default(), then
customize it using the builder-style with_* methods.
§Default values
| Field | Default |
|---|---|
batch_size | 32 |
send_buf_size (kernel SO_SNDBUF) | Not set (OS default) |
recv_os_buf_size (kernel SO_RCVBUF) | Not set (OS default) |
adaptive_batching | false |
metrics_enabled | false |
§Example
use binger_udp::Config;
let config = Config::new()
.with_batch_size(64)
.with_adaptive_batching(true);Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Config with default values.
Equivalent to Config::default().
Sourcepub fn with_batch_size(self, n: usize) -> Self
pub fn with_batch_size(self, n: usize) -> Self
Sets the target batch size for BingerUdp::send_batch and
BingerUdp::recv_batch operations.
The actual batch size used may be adjusted if adaptive batching is
enabled via Config::with_adaptive_batching.
Default: 32.
Sourcepub fn with_send_buf_size(self, n: usize) -> Self
pub fn with_send_buf_size(self, n: usize) -> Self
Sets the kernel send buffer size (SO_SNDBUF) for the socket.
This is an OS-level socket option that controls how much data the kernel buffers for sending. Larger values can improve throughput at the cost of memory.
Default: None (OS default is used).
Sourcepub fn with_recv_os_buf_size(self, n: usize) -> Self
pub fn with_recv_os_buf_size(self, n: usize) -> Self
Sets the kernel receive buffer size (SO_RCVBUF) for the socket.
This is an OS-level socket option. The kernel may double the requested value. Useful for high-throughput receivers that want to avoid packet drops in the kernel.
Default: None (OS default is used).
Sourcepub fn with_adaptive_batching(self, enabled: bool) -> Self
pub fn with_adaptive_batching(self, enabled: bool) -> Self
Enables or disables adaptive batching.
When enabled, the effective batch size is dynamically adjusted based on
the rate of WouldBlock events. The batch size is reduced when the
WouldBlock rate exceeds 30%, and increased when it drops below 10%.
Adjustments occur at most every 100 ms.
Default: false.
§Related
BingerUdp::recommended_batch_size— queries the current effective batch size.