2019-09-12 11:39:39 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2020-10-06 17:17:26 -07:00
|
|
|
use std::env;
|
2019-09-12 11:39:39 -07:00
|
|
|
//TODO remove this hack when rayon fixes itself
|
2019-09-18 18:00:07 -07:00
|
|
|
|
2019-09-12 11:39:39 -07:00
|
|
|
lazy_static! {
|
2019-10-17 20:55:05 -07:00
|
|
|
// reduce the number of threads each pool is allowed to half the cpu core count, to avoid rayon
|
|
|
|
// hogging cpu
|
2020-10-06 17:17:26 -07:00
|
|
|
static ref MAX_RAYON_THREADS: usize =
|
2022-06-13 12:16:58 -07:00
|
|
|
env::var("SOLANA_RAYON_THREADS").ok()
|
|
|
|
.and_then(|num_threads| num_threads.parse().ok())
|
2022-11-09 11:39:38 -08:00
|
|
|
.unwrap_or_else(|| num_cpus::get() / 2)
|
2022-06-13 12:16:58 -07:00
|
|
|
.max(1);
|
2019-09-12 11:39:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_thread_count() -> usize {
|
2019-10-17 20:55:05 -07:00
|
|
|
*MAX_RAYON_THREADS
|
2019-09-12 11:39:39 -07:00
|
|
|
}
|
2022-05-05 13:00:50 -07:00
|
|
|
|
|
|
|
// Only used in legacy code.
|
|
|
|
// Use get_thread_count instead in all new code.
|
|
|
|
pub fn get_max_thread_count() -> usize {
|
|
|
|
get_thread_count().saturating_mul(2)
|
|
|
|
}
|