From 7963237c431fee95c4e3c696a9ce6c63740db355 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Tue, 30 May 2023 14:30:16 +0300 Subject: [PATCH] to be dropped: mandatory PAGESERVER_THREADS_PER_RUNTIME --- control_plane/src/background_process.rs | 7 ++++++- pageserver/src/task_mgr.rs | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/control_plane/src/background_process.rs b/control_plane/src/background_process.rs index 1f3f8f45ea..f1c24b35aa 100644 --- a/control_plane/src/background_process.rs +++ b/control_plane/src/background_process.rs @@ -219,7 +219,12 @@ fn fill_rust_env_vars(cmd: &mut Command) -> &mut Command { let mut filled_cmd = cmd.env_clear().env("RUST_BACKTRACE", backtrace_setting); // Pass through these environment variables to the command - for var in ["LLVM_PROFILE_FILE", "FAILPOINTS", "RUST_LOG"] { + for var in [ + "LLVM_PROFILE_FILE", + "FAILPOINTS", + "RUST_LOG", + "PAGESERVER_THREADS_PER_RUNTIME", + ] { if let Some(val) = std::env::var_os(var) { filled_cmd = filled_cmd.env(var, val); } diff --git a/pageserver/src/task_mgr.rs b/pageserver/src/task_mgr.rs index b58f51665c..c8a505faf2 100644 --- a/pageserver/src/task_mgr.rs +++ b/pageserver/src/task_mgr.rs @@ -103,9 +103,23 @@ use crate::shutdown_pageserver; // other operations, if the upload tasks e.g. get blocked on locks. It shouldn't // happen, but still. // + +pub static THREADS_PER_RUNTIME: Lazy = Lazy::new(|| { + let num = std::env::var_os("PAGESERVER_THREADS_PER_RUNTIME") + .and_then(|var| var.to_str().map(|v| v.parse::())) + .expect("PAGESERVER_THREADS_PER_RUNTIME is unset") + .expect("PAGESERVER_THREADS_PER_RUNTIME is not an usize"); + + let num = + std::num::NonZeroUsize::new(num).expect("PAGESERVER_THREADS_PER_RUNTIME out of range"); + + num +}); + pub static COMPUTE_REQUEST_RUNTIME: Lazy = Lazy::new(|| { tokio::runtime::Builder::new_multi_thread() .thread_name("compute request worker") + .worker_threads(THREADS_PER_RUNTIME.get()) .enable_all() .build() .expect("Failed to create compute request runtime") @@ -114,6 +128,7 @@ pub static COMPUTE_REQUEST_RUNTIME: Lazy = Lazy::new(|| { pub static MGMT_REQUEST_RUNTIME: Lazy = Lazy::new(|| { tokio::runtime::Builder::new_multi_thread() .thread_name("mgmt request worker") + .worker_threads(THREADS_PER_RUNTIME.get()) .enable_all() .build() .expect("Failed to create mgmt request runtime") @@ -122,6 +137,7 @@ pub static MGMT_REQUEST_RUNTIME: Lazy = Lazy::new(|| { pub static WALRECEIVER_RUNTIME: Lazy = Lazy::new(|| { tokio::runtime::Builder::new_multi_thread() .thread_name("walreceiver worker") + .worker_threads(THREADS_PER_RUNTIME.get()) .enable_all() .build() .expect("Failed to create walreceiver runtime") @@ -130,6 +146,7 @@ pub static WALRECEIVER_RUNTIME: Lazy = Lazy::new(|| { pub static BACKGROUND_RUNTIME: Lazy = Lazy::new(|| { tokio::runtime::Builder::new_multi_thread() .thread_name("background op worker") + .worker_threads(THREADS_PER_RUNTIME.get()) .enable_all() .build() .expect("Failed to create background op runtime")