server: set minimum number of tokio worker threads
This commit is contained in:
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -1103,6 +1103,7 @@ dependencies = [
|
|||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"nix",
|
"nix",
|
||||||
|
"num_cpus",
|
||||||
"prettytable",
|
"prettytable",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -1178,6 +1179,16 @@ dependencies = [
|
|||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.3"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ indoc = "2.0.7"
|
|||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
nix = { version = "0.30.1", features = ["fs", "process", "socket", "user"] }
|
nix = { version = "0.30.1", features = ["fs", "process", "socket", "user"] }
|
||||||
|
num_cpus = "1.17.0"
|
||||||
prettytable = "0.10.0"
|
prettytable = "0.10.0"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
sd-notify = "0.4.5"
|
sd-notify = "0.4.5"
|
||||||
|
|||||||
11
src/main.rs
11
src/main.rs
@@ -188,17 +188,26 @@ fn handle_generate_completions_command(args: &Args) -> anyhow::Result<Option<()>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MIN_TOKIO_WORKER_THREADS: usize = 4;
|
||||||
|
|
||||||
/// Start a long-lived server using Tokio.
|
/// Start a long-lived server using Tokio.
|
||||||
fn tokio_start_server(
|
fn tokio_start_server(
|
||||||
config_path: Option<PathBuf>,
|
config_path: Option<PathBuf>,
|
||||||
verbosity: Verbosity,
|
verbosity: Verbosity,
|
||||||
args: ServerArgs,
|
args: ServerArgs,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let worker_thread_count = std::cmp::max(num_cpus::get(), MIN_TOKIO_WORKER_THREADS);
|
||||||
|
|
||||||
tokio::runtime::Builder::new_multi_thread()
|
tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(worker_thread_count)
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
.context("Failed to start Tokio runtime")?
|
.context("Failed to start Tokio runtime")?
|
||||||
.block_on(async { server::command::handle_command(config_path, verbosity, args).await })
|
.block_on(server::command::handle_command(
|
||||||
|
config_path,
|
||||||
|
verbosity,
|
||||||
|
args,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the given commmand (from the client side) using Tokio.
|
/// Run the given commmand (from the client side) using Tokio.
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ pub struct Supervisor {
|
|||||||
|
|
||||||
impl Supervisor {
|
impl Supervisor {
|
||||||
pub async fn new(config: ServerConfig, systemd_mode: bool) -> anyhow::Result<Self> {
|
pub async fn new(config: ServerConfig, systemd_mode: bool) -> anyhow::Result<Self> {
|
||||||
|
log::debug!("Starting server supervisor");
|
||||||
|
log::debug!(
|
||||||
|
"Running in tokio with {} worker threads",
|
||||||
|
tokio::runtime::Handle::current().metrics().num_workers()
|
||||||
|
);
|
||||||
|
|
||||||
let mut watchdog_duration = None;
|
let mut watchdog_duration = None;
|
||||||
let mut watchdog_micro_seconds = 0;
|
let mut watchdog_micro_seconds = 0;
|
||||||
let watchdog_task =
|
let watchdog_task =
|
||||||
|
|||||||
Reference in New Issue
Block a user