Skip to content

Commit

Permalink
Changing the default number of threads for the main tokio runtime. (#…
Browse files Browse the repository at this point in the history
…5124)

The new default value is num_cores / 3.
This value can be overridden using the QW_RUNTIME_NUM_THREADS
environment variable.

Closes #5123
  • Loading branch information
fulmicoton committed Jun 14, 2024
1 parent 674212b commit 8a69c73
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions quickwit/quickwit-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ use quickwit_common::runtimes::scrape_tokio_runtime_metrics;
use quickwit_serve::BuildInfo;
use tracing::error;

/// The main tokio runtime takes num_cores / 3 threads by default, and can be overridden by the
/// QW_RUNTIME_NUM_THREADS environment variable.
fn get_main_runtime_num_threads() -> usize {
let default_num_runtime_threads: usize = quickwit_common::num_cpus().div_ceil(3);
quickwit_common::get_from_env("QW_RUNTIME_NUM_THREADS", default_num_runtime_threads)
}

fn main() -> anyhow::Result<()> {
let main_runtime_num_threads: usize = get_main_runtime_num_threads();
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.on_thread_unpark(busy_detector::thread_unpark)
.on_thread_park(busy_detector::thread_park)
.thread_name("main_runtime_thread")
.worker_threads(main_runtime_num_threads)
.build()
.context("failed to start main Tokio runtime")?;

Expand Down

0 comments on commit 8a69c73

Please sign in to comment.