Limit Rayon threadpool threads (#5871)
This commit is contained in:
2
rayon-threadlimit/.gitignore
vendored
Normal file
2
rayon-threadlimit/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target/
|
||||
/farf/
|
13
rayon-threadlimit/Cargo.toml
Normal file
13
rayon-threadlimit/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "solana-rayon-threadlimit"
|
||||
version = "0.19.0-pre0"
|
||||
homepage = "https://solana.com/"
|
||||
readme = "../README.md"
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
sys-info = "0.5.7"
|
18
rayon-threadlimit/src/lib.rs
Normal file
18
rayon-threadlimit/src/lib.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use std::sync::RwLock;
|
||||
|
||||
//TODO remove this hack when rayon fixes itself
|
||||
lazy_static! {
|
||||
static ref MAX_RAYON_THREADS: RwLock<usize> =
|
||||
RwLock::new(sys_info::cpu_num().unwrap() as usize);
|
||||
}
|
||||
|
||||
pub fn get_thread_count() -> usize {
|
||||
*MAX_RAYON_THREADS.read().unwrap()
|
||||
}
|
||||
|
||||
pub fn set_thread_count(count: usize) {
|
||||
*MAX_RAYON_THREADS.write().unwrap() = count;
|
||||
}
|
Reference in New Issue
Block a user