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",
|
||||
"log",
|
||||
"nix",
|
||||
"num_cpus",
|
||||
"prettytable",
|
||||
"rand 0.9.2",
|
||||
"regex",
|
||||
@@ -1178,6 +1179,16 @@ dependencies = [
|
||||
"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]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
|
||||
@@ -31,6 +31,7 @@ indoc = "2.0.7"
|
||||
itertools = "0.14.0"
|
||||
log = "0.4.28"
|
||||
nix = { version = "0.30.1", features = ["fs", "process", "socket", "user"] }
|
||||
num_cpus = "1.17.0"
|
||||
prettytable = "0.10.0"
|
||||
rand = "0.9.2"
|
||||
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.
|
||||
fn tokio_start_server(
|
||||
config_path: Option<PathBuf>,
|
||||
verbosity: Verbosity,
|
||||
args: ServerArgs,
|
||||
) -> anyhow::Result<()> {
|
||||
let worker_thread_count = std::cmp::max(num_cpus::get(), MIN_TOKIO_WORKER_THREADS);
|
||||
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(worker_thread_count)
|
||||
.enable_all()
|
||||
.build()
|
||||
.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.
|
||||
|
||||
@@ -48,6 +48,12 @@ pub struct Supervisor {
|
||||
|
||||
impl Supervisor {
|
||||
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_micro_seconds = 0;
|
||||
let watchdog_task =
|
||||
|
||||
Reference in New Issue
Block a user