Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set thread counts for client & server using env variables with better defaults #1993

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use std::process;
use std::time::Duration;
use strip_ansi_escapes::Writer;
use tokio::io::AsyncReadExt;
use tokio::runtime;
use tokio::runtime::Runtime;
use walkdir::WalkDir;
use which::which_in;
Expand Down Expand Up @@ -771,7 +772,17 @@ pub fn run_command(cmd: Command) -> Result<i32> {
trace!("Command::Compile {{ {:?}, {:?}, {:?} }}", exe, cmdline, cwd);
let jobserver = unsafe { Client::new() };
let conn = connect_or_start_server(get_port(), startup_timeout)?;
let mut runtime = Runtime::new()?;

let worker_threads = env::var("SCCACHE_CLIENT_WORKER_THREADS")
sylvestre marked this conversation as resolved.
Show resolved Hide resolved
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(2);

let mut runtime = runtime::Builder::new_multi_thread()
.worker_threads(worker_threads)
.build()
.context("building tokio runtime")?;

let res = do_compile(
ProcessCommandCreator::new(&jobserver),
&mut runtime,
Expand Down
9 changes: 8 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,17 @@ pub fn start_server(config: &Config, port: u16) -> Result<()> {
panic_hook(info)
}));
let client = unsafe { Client::new() };

let worker_threads = env::var("SCCACHE_SERVER_WORKER_THREADS")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(std::cmp::max(20, num_cpus::get() * 2));

let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.worker_threads(std::cmp::max(20, 2 * num_cpus::get()))
.worker_threads(worker_threads)
.build()?;

let pool = runtime.handle().clone();
let dist_client = DistClientContainer::new(config, &pool);

Expand Down