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

feature(core): default tokio worker threads to std::thread::available_parallelism() #18541

Merged
merged 5 commits into from
Sep 14, 2023
Merged
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
22 changes: 9 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,17 @@ pub fn build_runtime(threads: Option<usize>, thread_name: &str) -> Result<Runtim
rt_builder.max_blocking_threads(20_000);
rt_builder.enable_all().thread_name(thread_name);

if let Some(threads) = threads {
if threads < 1 {
#[allow(clippy::print_stderr)]
{
eprintln!("The `threads` argument must be greater or equal to 1.");
}
return Err(exitcode::CONFIG);
} else {
WORKER_THREADS
.set(NonZeroUsize::new(threads).expect("already checked"))
.expect("double thread initialization");
rt_builder.worker_threads(threads);
}
let threads = threads.unwrap_or_else(crate::num_threads);
if threads < 1 {
error!("The `threads` argument must be greater or equal to 1.");
return Err(exitcode::CONFIG);
}
WORKER_THREADS
.set(NonZeroUsize::new(threads).expect("already checked"))
.expect("double thread initialization");
rt_builder.worker_threads(threads);

debug!(messaged = "Building runtime.", worker_threads = threads);
Ok(rt_builder.build().expect("Unable to create async runtime"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ We cover them below to help you upgrade quickly:
The `armv7` rpm package, `vector-<version>-1.armv7.rpm`, is now published as
`vector-<version>-1.armv7hl.rpm` to better follow rpm guidelines. The `armv7`
package will be no longer be published beginning in the 0.34.0 release.

### Potentially impactful changes

#### Async runtime default number of worker threads {#runtime-worker-threads}

We've changed the default number of worker threads spawned by Vector's async runtime
from being the number of CPUs on the host machine to the value returned by
[`std::thread::available_parallelism()`](https://doc.rust-lang.org/stable/std/thread/fn.available_parallelism.html).
This should be a better default value for containerized environments where the container
has limited quotas, but note this change may impact performance.

The number of worker threads used can be seen by enabling debug logging, and the value can
be overriden by setting the `VECTOR_THREADS` environment variable.