Skip to content

Commit 20fab1b

Browse files
committed
refactor(cli): run the benchmark off the tokio runtime
The benchmark is synchronous, CPU-bound work: dispatching it from inside the async main parked a tokio worker thread for the whole run. Split the startup preamble into a synchronous main that returns before the runtime starts, and move the node path into run_node, which now carries the #[tokio::main] attributes.
1 parent dd8a704 commit 20fab1b

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

bin/ethlambda/src/main.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ const ASCII_ART: &str = r#"
6767
\___|\__|_| |_|_|\__,_|_| |_| |_|_.__/ \__,_|\__,_|
6868
"#;
6969

70-
// Shadow single-steps execution in a discrete-event simulation, so the default
71-
// multi-threaded runtime's worker threads add only scheduling noise, never
72-
// parallelism. Use a single-threaded runtime under Shadow. This is an
73-
// optimization, not a correctness requirement.
74-
#[cfg_attr(not(feature = "shadow-integration"), tokio::main)]
75-
#[cfg_attr(feature = "shadow-integration", tokio::main(flavor = "current_thread"))]
76-
async fn main() -> eyre::Result<()> {
70+
fn main() -> eyre::Result<()> {
7771
let options = CliOptions::parse();
7872
options.validate_discovery()?;
7973

@@ -108,10 +102,23 @@ async fn main() -> eyre::Result<()> {
108102
ethlambda_blockchain::metrics::set_node_info("ethlambda", version::CLIENT_VERSION);
109103
ethlambda_blockchain::metrics::set_node_start_time();
110104

105+
// The benchmark is synchronous, CPU-bound work: run it on the main thread
106+
// and never start the tokio runtime, rather than parking a worker thread
107+
// for the whole run.
111108
if let Some(cli::Command::Benchmark(benchmark_options)) = options.command {
112109
return benchmark::run(benchmark_options);
113110
}
114111

112+
run_node(options)
113+
}
114+
115+
// Shadow single-steps execution in a discrete-event simulation, so the default
116+
// multi-threaded runtime's worker threads add only scheduling noise, never
117+
// parallelism. Use a single-threaded runtime under Shadow. This is an
118+
// optimization, not a correctness requirement.
119+
#[cfg_attr(not(feature = "shadow-integration"), tokio::main)]
120+
#[cfg_attr(feature = "shadow-integration", tokio::main(flavor = "current_thread"))]
121+
async fn run_node(options: CliOptions) -> eyre::Result<()> {
115122
let rpc_config = RpcConfig {
116123
http_address: options.http_address,
117124
api_port: options.api_port,

0 commit comments

Comments
 (0)