trezoa_rayon_threadlimit/
lib.rs

1use {log::warn, std::env};
2//TODO remove this hack when rayon fixes itself
3
4// reduce the number of threads each pool is allowed to half the cpu core count, to avoid rayon
5// hogging cpu
6static MAX_RAYON_THREADS: std::sync::LazyLock<usize> = std::sync::LazyLock::new(|| {
7    env::var("TREZOA_RAYON_THREADS")
8        .ok()
9        .and_then(|num_threads| {
10            warn!(
11                "Use of TREZOA_RAYON_THREADS has been deprecated and will be removed soon. Use \
12                 the individual agave-validator CLI flags to configure threadpool sizes"
13            );
14            num_threads.parse().ok()
15        })
16        .unwrap_or_else(|| num_cpus::get() / 2)
17        .max(1)
18});
19
20pub fn get_thread_count() -> usize {
21    *MAX_RAYON_THREADS
22}
23
24#[deprecated(
25    since = "3.0.0",
26    note = "The trezoa-rayon-threadlimit crate will be removed, use num_cpus::get() or something \
27            similar instead"
28)]
29pub fn get_max_thread_count() -> usize {
30    get_thread_count().saturating_mul(2)
31}