Skip to content

Commit

Permalink
feature(core): default tokio worker threads to `std::thread::availabl…
Browse files Browse the repository at this point in the history
…e_parallelism()` (vectordotdev#18541)

* default tokio worker threads to std::thread::available_parallelism()

* update log

* rename log field

* add upgrade guide entry

* fmt
  • Loading branch information
dsmith3197 authored Sep 14, 2023
1 parent ddb5195 commit 730bb15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
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
13 changes: 13 additions & 0 deletions website/content/en/highlights/2023-09-26-0-33-0-upgrade-guide.md
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.

0 comments on commit 730bb15

Please sign in to comment.