Skip to content

Commit 730bb15

Browse files
authored
feature(core): default tokio worker threads to std::thread::available_parallelism() (vectordotdev#18541)
* default tokio worker threads to std::thread::available_parallelism() * update log * rename log field * add upgrade guide entry * fmt
1 parent ddb5195 commit 730bb15

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/app.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,17 @@ pub fn build_runtime(threads: Option<usize>, thread_name: &str) -> Result<Runtim
467467
rt_builder.max_blocking_threads(20_000);
468468
rt_builder.enable_all().thread_name(thread_name);
469469

470-
if let Some(threads) = threads {
471-
if threads < 1 {
472-
#[allow(clippy::print_stderr)]
473-
{
474-
eprintln!("The `threads` argument must be greater or equal to 1.");
475-
}
476-
return Err(exitcode::CONFIG);
477-
} else {
478-
WORKER_THREADS
479-
.set(NonZeroUsize::new(threads).expect("already checked"))
480-
.expect("double thread initialization");
481-
rt_builder.worker_threads(threads);
482-
}
470+
let threads = threads.unwrap_or_else(crate::num_threads);
471+
if threads < 1 {
472+
error!("The `threads` argument must be greater or equal to 1.");
473+
return Err(exitcode::CONFIG);
483474
}
475+
WORKER_THREADS
476+
.set(NonZeroUsize::new(threads).expect("already checked"))
477+
.expect("double thread initialization");
478+
rt_builder.worker_threads(threads);
484479

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

website/content/en/highlights/2023-09-26-0-33-0-upgrade-guide.md

+13
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ We cover them below to help you upgrade quickly:
2424
The `armv7` rpm package, `vector-<version>-1.armv7.rpm`, is now published as
2525
`vector-<version>-1.armv7hl.rpm` to better follow rpm guidelines. The `armv7`
2626
package will be no longer be published beginning in the 0.34.0 release.
27+
28+
### Potentially impactful changes
29+
30+
#### Async runtime default number of worker threads {#runtime-worker-threads}
31+
32+
We've changed the default number of worker threads spawned by Vector's async runtime
33+
from being the number of CPUs on the host machine to the value returned by
34+
[`std::thread::available_parallelism()`](https://doc.rust-lang.org/stable/std/thread/fn.available_parallelism.html).
35+
This should be a better default value for containerized environments where the container
36+
has limited quotas, but note this change may impact performance.
37+
38+
The number of worker threads used can be seen by enabling debug logging, and the value can
39+
be overriden by setting the `VECTOR_THREADS` environment variable.

0 commit comments

Comments
 (0)