Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how we handle control-c in stress #4723

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

1 change: 1 addition & 0 deletions crates/sui-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ duration-str = "0.4.0"
hdrhistogram = "7.5.1"
comfy-table = "6.1.0"
bcs = "0.1.3"
tokio-util = "0.7.4"
sui-core = { path = "../sui-core" }
sui-config = { path = "../sui-config" }
sui-types = { path = "../sui-types" }
Expand Down
18 changes: 16 additions & 2 deletions crates/sui-benchmark/src/drivers/bench_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use prometheus::IntCounterVec;
use prometheus::Registry;
use sui_core::authority_aggregator::AuthorityAggregator;
use tokio::sync::OnceCell;
use tokio_util::sync::CancellationToken;

use crate::drivers::driver::Driver;
use crate::drivers::HistogramWrapper;
Expand Down Expand Up @@ -143,15 +144,20 @@ pub struct BenchWorker {
pub struct BenchDriver {
pub stat_collection_interval: u64,
pub start_time: Instant,
pub token: CancellationToken,
}

impl BenchDriver {
pub fn new(stat_collection_interval: u64) -> BenchDriver {
BenchDriver {
stat_collection_interval,
start_time: Instant::now(),
token: CancellationToken::new(),
}
}
pub fn terminate(&self) {
self.token.cancel()
}
pub fn update_progress(
start_time: Instant,
interval: Interval,
Expand Down Expand Up @@ -242,6 +248,7 @@ impl Driver<BenchmarkStats> for BenchDriver {
});
for (i, worker) in bench_workers.into_iter().enumerate() {
let committee = committee.clone();
let cloned_token = self.token.clone();
let request_delay_micros = 1_000_000 / worker.target_qps;
let mut free_pool = worker.payload;
let progress = progress.clone();
Expand Down Expand Up @@ -272,7 +279,7 @@ impl Driver<BenchmarkStats> for BenchDriver {
let mut stat_start_time: Instant = Instant::now();
loop {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
_ = cloned_token.cancelled() => {
break;
}
_ = stat_interval.tick() => {
Expand Down Expand Up @@ -515,7 +522,14 @@ impl Driver<BenchmarkStats> for BenchDriver {
benchmark_stat
});
drop(tx);
let _res: Vec<_> = try_join_all(tasks).await.unwrap().into_iter().collect();
let all_tasks = try_join_all(tasks);
let _res = tokio::select! {
_ = tokio::signal::ctrl_c() => {
self.terminate();
vec![]
}
res = all_tasks => res.unwrap().into_iter().collect()
};
let benchmark_stat = stat_task.await.unwrap();
Ok(benchmark_stat)
}
Expand Down