Skip to content

Commit

Permalink
Gracefully shutdown benchmark (#3326)
Browse files Browse the repository at this point in the history
## Motivation

Right now if you interrupt the benchmark, it might leave you in a state where the local node is inconsistent with the validators, the wallet hasn't been saved... etc

## Proposal

Gracefully shutdown the benchmark on interruption signals, making sure we never exit in the middle of sending a block proposal, and only saving the wallet on program exit.

## Test Plan

Ran the benchmark locally, did Ctrl+C and saw it gracefully exit.

## Release Plan

- Nothing to do / These changes follow the usual release cycle.
  • Loading branch information
ndr-ds authored Feb 14, 2025
1 parent f703843 commit 260a680
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion linera-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version.workspace = true

[features]
test = ["linera-views/test", "linera-execution/test"]
benchmark = ["linera-base/test", "dep:linera-sdk"]
benchmark = ["linera-base/test", "dep:linera-sdk", "dep:tokio-util"]
wasmer = [
"linera-core/wasmer",
"linera-execution/wasmer",
Expand Down Expand Up @@ -75,6 +75,7 @@ thiserror.workspace = true
thiserror-context.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tokio-util = { workspace = true, optional = true }
tracing.workspace = true
trait-variant.workspace = true

Expand Down
12 changes: 11 additions & 1 deletion linera-client/src/client_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use {
data_types::Amount,
hashed::Hashed,
identifiers::{AccountOwner, ApplicationId, Owner},
listen_for_shutdown_signals,
},
linera_chain::{
data_types::{BlockProposal, ExecutedBlock, ProposedBlock, SignatureAggregator, Vote},
Expand All @@ -57,6 +58,7 @@ use {
linera_sdk::abis::fungible,
std::{collections::HashMap, iter},
tokio::task,
tokio_util::sync::CancellationToken,
tracing::{error, trace, warn},
};

Expand Down Expand Up @@ -571,9 +573,17 @@ where
transactions_per_block: usize,
epoch: Epoch,
) -> Result<(), Error> {
let shutdown_notifier = CancellationToken::new();
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));

let mut num_sent_proposals = 0;
let mut start = Instant::now();
for (chain_id, operations, key_pair) in blocks_infos_iter {
if shutdown_notifier.is_cancelled() {
info!("Shutdown signal received, stopping benchmark");
self.save_wallet().await?;
return Ok(());
}
let chain = self.wallet.get(*chain_id).expect("should have chain");
let block = ProposedBlock {
epoch,
Expand Down Expand Up @@ -664,6 +674,7 @@ where
}

if bps.is_none() {
self.save_wallet().await?;
let elapsed = start.elapsed();
let bps = num_sent_proposals as f64 / elapsed.as_secs_f64();
info!(
Expand Down Expand Up @@ -1046,7 +1057,6 @@ where
chain.block_hash = info.block_hash;
chain.next_block_height = info.next_block_height;
}
self.save_wallet().await.unwrap();
}

/// Creates a fungible token transfer operation.
Expand Down

0 comments on commit 260a680

Please sign in to comment.