Skip to main content

mundis_rayon_threadlimit/
lib.rs

1#[macro_use]
2extern crate lazy_static;
3
4use std::env;
5//TODO remove this hack when rayon fixes itself
6
7lazy_static! {
8    // reduce the number of threads each pool is allowed to half the cpu core count, to avoid rayon
9    // hogging cpu
10    static ref MAX_RAYON_THREADS: usize =
11            env::var("MUNDIS_RAYON_THREADS")
12                .map(|x| x.parse().unwrap_or(num_cpus::get() as usize / 2))
13                .unwrap_or(num_cpus::get() as usize / 2);
14}
15
16pub fn get_thread_count() -> usize {
17    *MAX_RAYON_THREADS
18}