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 all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded)

And you can build code as usual without any additional flags in the command line, useful for IDEs.

To limit the number of threads sccache process spawns, use `SCCACHE_SERVER_WORKER_THREADS` and `SCCACHE_CLIENT_WORKER_THREADS` environment variables for server and client processes respectively.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explain in which contexts someone might need this


---

Expand Down
14 changes: 13 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,18 @@ 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()
.enable_all()
.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