forked from faasten/faasten
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rs
51 lines (41 loc) · 1.44 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use clap::Parser;
use std::{
sync::{Arc, Condvar, Mutex},
thread,
};
use snapfaas::sched::{resource_manager::ResourceManager, rpc_server::RpcServer, schedule};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Address to listen at
#[arg(short, long, value_name = "ADDR:PORT")]
listen: String,
/// Capacity of the request queue
#[arg(short, long, value_name = "CAP_NUM_OF_TASK", default_value_t = 1000000)]
qcap: u32,
}
fn main() {
env_logger::init();
let cli = Cli::parse();
// Intialize remote scheduler
let (queue_tx, queue_rx) = crossbeam::channel::bounded(cli.qcap as usize);
let manager = Arc::new(Mutex::new(ResourceManager::new()));
let cvar = Arc::new(Condvar::new());
// Register signal handler
set_ctrlc_handler(manager.clone());
// kick off scheduling thread
let manager_dup = manager.clone();
let cvar_dup = cvar.clone();
thread::spawn(move || schedule(queue_rx, manager_dup, cvar_dup));
let s = RpcServer::new(&cli.listen, manager.clone(), queue_tx, cvar);
log::debug!("Scheduler starts listening at {:?}", cli.listen);
s.run();
}
fn set_ctrlc_handler(manager: Arc<Mutex<ResourceManager>>) {
ctrlc::set_handler(move || {
log::warn!("{}", "Handling Ctrl-C. Shutting down...");
manager.lock().unwrap().remove_all();
std::process::exit(0);
})
.expect("Error setting Ctrl-C handler");
}