diff --git a/bastion-executor/src/distributor.rs b/bastion-executor/src/distributor.rs index d7f0282b..ba5af4fe 100644 --- a/bastion-executor/src/distributor.rs +++ b/bastion-executor/src/distributor.rs @@ -19,16 +19,19 @@ impl Distributor { } } - pub fn assign

(mut self, thunk: P) -> Vec> + pub fn assign

(mut self, thunk: P) -> (Vec>, Vec>) where P: Fn() + Send + Sync + Copy + 'static, { let mut stealers = Vec::>::new(); + let mut workers = Vec::>::new(); + for core in self.cores { self.round = core.id; let worker = Worker::new_fifo(); stealers.push(worker.stealer()); + workers.push(worker); thread::Builder::new() .name("bastion-async-thread".to_string()) @@ -42,6 +45,6 @@ impl Distributor { .expect("cannot start the thread for running proc"); } - stealers + (stealers, workers) } } diff --git a/bastion-executor/src/load_balancer.rs b/bastion-executor/src/load_balancer.rs index 5f648727..cae48034 100644 --- a/bastion-executor/src/load_balancer.rs +++ b/bastion-executor/src/load_balancer.rs @@ -1,5 +1,7 @@ use lazy_static::*; -use std::thread; +use std::{thread, time}; + +const SIXTY_MILLIS: time::Duration = time::Duration::from_millis(60); pub struct LoadBalancer(); @@ -17,6 +19,10 @@ pub(crate) fn launch() -> &'static LoadBalancer { .name("load-balancer-thread".to_string()) .spawn(|| { + // General suspending is equal to cache line size in ERTS + // https://github.com/erlang/otp/blob/master/erts/emulator/beam/erl_process.c#L10887 + // https://github.com/erlang/otp/blob/ea7d6c39f2179b2240d55df4a1ddd515b6d32832/erts/emulator/beam/erl_thr_progress.c#L237 + thread::sleep(SIXTY_MILLIS) }) .expect("load-balancer couldn't start"); diff --git a/bastion-executor/src/pool.rs b/bastion-executor/src/pool.rs index 1a86aff5..a7fd30a1 100644 --- a/bastion-executor/src/pool.rs +++ b/bastion-executor/src/pool.rs @@ -27,7 +27,7 @@ pub fn get() -> &'static Pool { lazy_static! { static ref POOL: Pool = { let distributor = Distributor::new(); - let stealers = distributor.assign(|| { + let (stealers, workers) = distributor.assign(|| { println!("1,2,3"); });