summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2025-05-15 09:50:09 +0200
committerDavid Lönnhager <david.l@mullvad.net>2025-05-15 09:50:09 +0200
commitddeaee1ef104ca39fb57647b08cedda8e61bab2b (patch)
tree18adcee7db12ba97e60e3874136c7e4f178cc2b5
parente191432724e7c2f07953704a8fc875e4ccf9f55e (diff)
parent44a55e1c33d059521e8194b84d3c4cc68d1a2159 (diff)
downloadmullvadvpn-ddeaee1ef104ca39fb57647b08cedda8e61bab2b.tar.xz
mullvadvpn-ddeaee1ef104ca39fb57647b08cedda8e61bab2b.zip
Merge branch 'enable-all-worker-threads'
-rw-r--r--.github/workflows/rust-unused-dependencies.yml2
-rw-r--r--mullvad-daemon/src/runtime.rs15
2 files changed, 15 insertions, 2 deletions
diff --git a/.github/workflows/rust-unused-dependencies.yml b/.github/workflows/rust-unused-dependencies.yml
index 47c58bcca2..d00c9b5c26 100644
--- a/.github/workflows/rust-unused-dependencies.yml
+++ b/.github/workflows/rust-unused-dependencies.yml
@@ -10,7 +10,7 @@ on:
workflow_dispatch:
env:
# Pinning nightly just to avoid random breakage. It's fine to bump this at any time
- RUST_NIGHTLY_TOOLCHAIN: nightly-2024-10-02
+ RUST_NIGHTLY_TOOLCHAIN: nightly-2025-05-14
permissions: {}
diff --git a/mullvad-daemon/src/runtime.rs b/mullvad-daemon/src/runtime.rs
index 86d251db4c..5f4521ed01 100644
--- a/mullvad-daemon/src/runtime.rs
+++ b/mullvad-daemon/src/runtime.rs
@@ -1,8 +1,21 @@
+use std::num::NonZero;
use tokio::runtime;
+const MIN_NUM_THREADS: NonZero<usize> = NonZero::new(4).unwrap();
+
pub fn new_multi_thread() -> runtime::Builder {
let mut builder = runtime::Builder::new_multi_thread();
- builder.worker_threads(4).enable_all();
+ match std::thread::available_parallelism() {
+ Ok(num_cpus) if num_cpus < MIN_NUM_THREADS => {
+ builder.worker_threads(MIN_NUM_THREADS.into());
+ }
+ // Use default number of workers
+ Ok(_) => (),
+ Err(error) => {
+ log::warn!("Failed to retrieve number of CPU cores: {error}");
+ }
+ }
+ builder.enable_all();
builder
}