From 53d40ceeabb243963bd30eee512e125ab11999d4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 21 Jun 2022 10:09:53 +0200 Subject: [PATCH] rt: set worker thread count use at least 2 but at most 4 worker threads Signed-off-by: Wolfgang Bumiller --- Cargo.toml | 3 ++- src/main.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 522ba2e..f48f577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,10 @@ homepage = "https://www.proxmox.com" exclude = [ "build", "debian" ] [dependencies] -bitflags = "1.2" anyhow = "1.0" +bitflags = "1.2" lazy_static = "1.4" libc = "0.2" nix = "0.24" +num_cpus = "1" tokio = { version = "1.0", features = [ "rt-multi-thread", "io-util", "net" ] } diff --git a/src/main.rs b/src/main.rs index 118423d..efa6979 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,13 @@ fn main() { } }; - let rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime"); + let cpus = num_cpus::get(); + + let rt = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .worker_threads(cpus.max(2).min(4)) + .build() + .expect("failed to spawn tokio runtime"); if let Err(err) = rt.block_on(do_main(use_sd_notify, path)) { eprintln!("error: {}", err);