Skip to content

Commit

Permalink
Load balancer schedule timing
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Oct 27, 2019
1 parent 2cb4ae3 commit 8301043
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions bastion-executor/src/distributor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ impl Distributor {
}
}

pub fn assign<P>(mut self, thunk: P) -> Vec<Stealer<LightProc>>
pub fn assign<P>(mut self, thunk: P) -> (Vec<Stealer<LightProc>>, Vec<Worker<LightProc>>)
where
P: Fn() + Send + Sync + Copy + 'static,
{
let mut stealers = Vec::<Stealer<LightProc>>::new();
let mut workers = Vec::<Worker<LightProc>>::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())
Expand All @@ -42,6 +45,6 @@ impl Distributor {
.expect("cannot start the thread for running proc");
}

stealers
(stealers, workers)
}
}
8 changes: 7 additions & 1 deletion bastion-executor/src/load_balancer.rs
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion bastion-executor/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down

0 comments on commit 8301043

Please sign in to comment.