Skip to content

Commit 14e0652

Browse files
committed
use runtime flag and default to tpc
1 parent 44679f2 commit 14e0652

1 file changed

Lines changed: 43 additions & 26 deletions

File tree

pulsebeam/src/main.rs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,29 @@ pub static malloc_conf: &[u8] = b"background_thread:false,max_background_threads
2121
// #[global_allocator]
2222
// static GLOBAL: MiMalloc = MiMalloc;
2323

24+
#[derive(clap::ValueEnum, Clone, Debug, Copy, PartialEq)]
25+
pub enum RtMode {
26+
/// Thread-per-core (default)
27+
Tpc,
28+
/// Work-stealing
29+
Stealing,
30+
}
31+
2432
#[derive(Parser, Debug)]
2533
#[command(version, about, long_about = None)]
2634
struct Args {
2735
/// Enable development mode preset
2836
#[arg(short, long)]
2937
dev: bool,
3038

31-
/// Enable thread-per-core runtime mode
32-
#[arg(short, long)]
33-
tpc: bool,
39+
/// Runtime mode
40+
#[arg(
41+
long = "runtime",
42+
visible_alias = "rt",
43+
value_enum,
44+
default_value_t = RtMode::Tpc
45+
)]
46+
pub rt: RtMode,
3447
}
3548

3649
trait Runtime {
@@ -81,33 +94,37 @@ fn main() {
8194
total_cores
8295
);
8396

84-
let rt = if args.tpc {
85-
let mut rt_builder = tokio::runtime::Builder::new_current_thread();
86-
let rt = rt_builder
87-
.enable_all()
88-
// .worker_threads(workers)
89-
// .disable_lifo_slot()
90-
// https://github.com/tokio-rs/tokio/issues/7745
91-
.enable_alt_timer()
92-
.build_local(LocalOptions::default())
93-
.unwrap();
94-
PulsebeamRuntime::LocalRuntime(rt)
95-
} else {
96-
let mut rt_builder = tokio::runtime::Builder::new_multi_thread();
97-
let rt = rt_builder
98-
.enable_all()
99-
// .worker_threads(workers)
100-
// .disable_lifo_slot()
101-
// https://github.com/tokio-rs/tokio/issues/7745
102-
.enable_alt_timer()
103-
.build()
104-
.unwrap();
105-
PulsebeamRuntime::MultiThreadedRuntime(rt)
97+
let rt = match args.rt {
98+
RtMode::Tpc => {
99+
let mut rt_builder = tokio::runtime::Builder::new_current_thread();
100+
let rt = rt_builder
101+
.enable_all()
102+
// .worker_threads(workers)
103+
// .disable_lifo_slot()
104+
// https://github.com/tokio-rs/tokio/issues/7745
105+
.enable_alt_timer()
106+
.build_local(LocalOptions::default())
107+
.unwrap();
108+
PulsebeamRuntime::LocalRuntime(rt)
109+
}
110+
RtMode::Stealing => {
111+
let mut rt_builder = tokio::runtime::Builder::new_multi_thread();
112+
let rt = rt_builder
113+
.enable_all()
114+
// .worker_threads(workers)
115+
// .disable_lifo_slot()
116+
// https://github.com/tokio-rs/tokio/issues/7745
117+
.enable_alt_timer()
118+
.build()
119+
.unwrap();
120+
PulsebeamRuntime::MultiThreadedRuntime(rt)
121+
}
106122
};
107123

108124
let rtc_port: u16 = if args.dev { 3478 } else { 443 };
109125
let shutdown = CancellationToken::new();
110-
rt.block_on(run(shutdown.clone(), workers, rtc_port, !args.tpc));
126+
let shared_runtime = matches!(args.rt, RtMode::Stealing);
127+
rt.block_on(run(shutdown.clone(), workers, rtc_port, shared_runtime));
111128
shutdown.cancel();
112129
}
113130

0 commit comments

Comments
 (0)