Skip to main content

tako_rs_server_pt/
config.rs

1use std::time::Duration;
2
3/// Configuration for [`serve_per_thread`](crate::serve_per_thread) (and the `compio` variant when enabled).
4#[derive(Debug, Clone)]
5pub struct PerThreadConfig {
6  /// Number of worker threads. Defaults to the number of logical CPUs.
7  pub workers: usize,
8  /// Pin each worker to a CPU core (requires the `affinity` feature).
9  pub pin_to_core: bool,
10  /// `SO_REUSEPORT` listen backlog.
11  pub backlog: i32,
12  /// Maximum time the coordinator waits for in-flight requests after shutdown.
13  /// Workers are dropped after this elapses.
14  pub drain_timeout: Duration,
15}
16
17impl Default for PerThreadConfig {
18  fn default() -> Self {
19    Self {
20      workers: num_cpus(),
21      pin_to_core: cfg!(feature = "affinity"),
22      backlog: 1024,
23      drain_timeout: Duration::from_secs(30),
24    }
25  }
26}
27
28fn num_cpus() -> usize {
29  std::thread::available_parallelism().map_or(1, std::num::NonZero::get)
30}