diff --git a/Cargo.lock b/Cargo.lock index d7b1b3e53152..26ce5cc2b407 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2123,6 +2123,7 @@ dependencies = [ "paramfetch", "pretty_env_logger", "prometheus", + "rayon", "rpassword", "rpc", "rpc-client", @@ -3281,6 +3282,7 @@ dependencies = [ "log", "networks", "num-traits", + "num_cpus", "rayon", "state_tree", ] diff --git a/forest/Cargo.toml b/forest/Cargo.toml index fa95ec4cd325..bb67989c38a0 100644 --- a/forest/Cargo.toml +++ b/forest/Cargo.toml @@ -45,6 +45,7 @@ paramfetch = { path = "../utils/paramfetch" } encoding = { package = "forest_encoding", version = "0.2.1" } networks = { path = "../types/networks" } rpassword = "0.0.4" +rayon = "1.5" prometheus = { version = "0.12.0", default-features = false } [dependencies.jsonrpc-v2] diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index a8dde56dc9b3..730db0a857c1 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -37,6 +37,12 @@ pub(super) async fn start(config: Config) { .set(address::Network::Mainnet) .unwrap(); + // Configure the Rayon Threadpool + rayon::ThreadPoolBuilder::new() + .thread_name(|n| format!("rayon-thread-{}", n)) + .build_global() + .expect("Failed to create global Rayon ThreadPool"); + info!("Starting Forest daemon"); let net_keypair = get_keypair(&format!("{}{}", &config.data_dir, "/libp2p/keypair")) .unwrap_or_else(|| { diff --git a/vm/interpreter/Cargo.toml b/vm/interpreter/Cargo.toml index 13d1c6110186..85e80d86b6b4 100644 --- a/vm/interpreter/Cargo.toml +++ b/vm/interpreter/Cargo.toml @@ -27,6 +27,7 @@ ahash = "0.6" lazy_static = "1.4" rayon = "1.3" networks = { path = "../../types/networks" } +num_cpus = "1.13" [dev-dependencies] ipld_hamt = "1.0" diff --git a/vm/interpreter/src/default_runtime.rs b/vm/interpreter/src/default_runtime.rs index 4880ac37e2e8..1b3109636759 100644 --- a/vm/interpreter/src/default_runtime.rs +++ b/vm/interpreter/src/default_runtime.rs @@ -41,6 +41,10 @@ use vm::{ EMPTY_ARR_CID, METHOD_SEND, }; +lazy_static! { + static ref NUM_CPUS: usize = num_cpus::get(); +} + /// Max runtime call depth const MAX_CALL_DEPTH: u64 = 4096; @@ -987,6 +991,7 @@ where let out = vis .par_iter() + .with_min_len(vis.len() / *NUM_CPUS) .map(|(&addr, seals)| { let results = seals .par_iter()