diff --git a/backend/telemetry_core/src/main.rs b/backend/telemetry_core/src/main.rs index 0c38214..4802d80 100644 --- a/backend/telemetry_core/src/main.rs +++ b/backend/telemetry_core/src/main.rs @@ -60,9 +60,9 @@ struct Opts { #[structopt(long, default_value = "10")] feed_timeout: u64, /// Number of worker threads to spawn. If "0" is given, use the number of CPUs available - /// on the machine. - #[structopt(long, default_value = "0")] - worker_threads: usize, + /// on the machine. If no value is given, use an internal default that we have deemed sane. + #[structopt(long)] + worker_threads: Option, } fn main() { @@ -76,8 +76,9 @@ fn main() { log::info!("Starting Telemetry Core version: {}", VERSION); let worker_threads = match opts.worker_threads { - 0 => num_cpus::get(), - n => n, + Some(0) => num_cpus::get(), + Some(n) => n, + None => usize::min(num_cpus::get(), 8) }; tokio::runtime::Builder::new_multi_thread() diff --git a/backend/telemetry_shard/src/main.rs b/backend/telemetry_shard/src/main.rs index dc8723d..67b96ce 100644 --- a/backend/telemetry_shard/src/main.rs +++ b/backend/telemetry_shard/src/main.rs @@ -81,9 +81,9 @@ struct Opts { #[structopt(long, default_value = "600")] node_block_seconds: u64, /// Number of worker threads to spawn. If "0" is given, use the number of CPUs available - /// on the machine. - #[structopt(long, default_value = "0")] - worker_threads: usize, + /// on the machine. If no value is given, use an internal default that we have deemed sane. + #[structopt(long)] + worker_threads: Option, } fn main() { @@ -97,8 +97,11 @@ fn main() { log::info!("Starting Telemetry Shard version: {}", VERSION); let worker_threads = match opts.worker_threads { - 0 => num_cpus::get(), - n => n, + Some(0) => num_cpus::get(), + Some(n) => n, + // By default, use a max of 4 worker threads, as we don't + // expect to need a lot of parallelism in shards. + None => usize::min(num_cpus::get(), 4) }; tokio::runtime::Builder::new_multi_thread()