Browse Source

run executor with the number of CPUs available

ghassmo 4 years ago
parent
commit
9c9d749cc9
3 changed files with 19 additions and 6 deletions
  1. 6 2
      src/bin/cashierd.rs
  2. 6 2
      src/bin/darkfid.rs
  3. 7 2
      src/bin/gatewayd.rs

+ 6 - 2
src/bin/cashierd.rs

@@ -750,9 +750,13 @@ async fn main() -> Result<()> {
 
     let get_address_flag = args.is_present("ADDRESS");
 
+    let nthreads = num_cpus::get();
+    debug!(target: "GATEWAY DAEMON", "Run {} executor threads", nthreads);
+
     let (_, result) = Parallel::new()
-        // Run four executor threads.
-        .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
+        .each(0..nthreads, |_| {
+            smol::future::block_on(ex.run(shutdown.recv()))
+        })
         // Run the main future on the current thread.
         .finish(|| {
             smol::future::block_on(async move {

+ 6 - 2
src/bin/darkfid.rs

@@ -611,9 +611,13 @@ async fn main() -> Result<()> {
 
     let ex2 = ex.clone();
 
+    let nthreads = num_cpus::get();
+    debug!(target: "GATEWAY DAEMON", "Run {} executor threads", nthreads);
+
     let (_, result) = Parallel::new()
-        // Run four executor threads.
-        .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
+        .each(0..nthreads, |_| {
+            smol::future::block_on(ex.run(shutdown.recv()))
+        })
         // Run the main future on the current thread.
         .finish(|| {
             smol::future::block_on(async move {

+ 7 - 2
src/bin/gatewayd.rs

@@ -4,6 +4,7 @@ use std::sync::Arc;
 use async_executor::Executor;
 use clap::clap_app;
 use easy_parallel::Parallel;
+use log::debug;
 
 use drk::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
@@ -57,9 +58,13 @@ async fn main() -> Result<()> {
 
     let ex2 = ex.clone();
 
+    let nthreads = num_cpus::get();
+    debug!(target: "GATEWAY DAEMON", "Run {} executor threads", nthreads);
+
     let (_, result) = Parallel::new()
-        // Run four executor threads.
-        .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
+        .each(0..nthreads, |_| {
+            smol::future::block_on(ex.run(shutdown.recv()))
+        })
         // Run the main future on the current thread.
         .finish(|| {
             smol::future::block_on(async move {