From 1c2dc20b5e8467e4f02ccdd37c3e373b9f803a59 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Mon, 9 Dec 2024 03:07:31 -0500 Subject: [PATCH] Wait for at least one account to have been created before starting the account benchmarks (#3960) --- accounts-cluster-bench/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index ed0581afcbbe5d..a465d0c07a1dc8 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -33,7 +33,7 @@ use { str::FromStr, sync::{ atomic::{AtomicBool, AtomicU64, Ordering}, - Arc, + Arc, Barrier, }, thread::{sleep, Builder, JoinHandle}, time::{Duration, Instant}, @@ -508,6 +508,7 @@ fn run_rpc_bench_loop( fn make_rpc_bench_threads( rpc_benches: Vec, mint: &Option, + start_bench_barrier: &Arc, exit: &Arc, client: &Arc, seed_tracker: &SeedTracker, @@ -524,6 +525,7 @@ fn make_rpc_bench_threads( .flat_map(|rpc_bench| { (0..num_rpc_bench_threads).map(move |thread| { let client = client.clone(); + let start_bench = start_bench_barrier.clone(); let exit = exit.clone(); let max_closed = seed_tracker.max_closed.clone(); let max_created = seed_tracker.max_created.clone(); @@ -531,6 +533,7 @@ fn make_rpc_bench_threads( Builder::new() .name(format!("rpc-bench-{}", thread)) .spawn(move || { + start_bench.wait(); run_rpc_bench_loop( rpc_bench, thread, @@ -617,11 +620,17 @@ fn run_accounts_bench( ); let exit = Arc::new(AtomicBool::new(false)); + let mut start_bench_barrier = Some(Arc::new(Barrier::new( + // In order to unlock the benchmark threads, `wait()` must be called on each thread and then + // once from this thread, after the first pass through the account creation loop. + num_rpc_bench_threads + 1, + ))); let base_keypair_pubkey = base_keypair.pubkey(); let rpc_bench_threads: Vec<_> = if let Some(rpc_benches) = rpc_benches { make_rpc_bench_threads( rpc_benches, &mint, + start_bench_barrier.as_ref().unwrap(), &exit, &client, &seed_tracker, @@ -732,6 +741,12 @@ fn run_accounts_bench( let _ = executor.drain_cleared(); } + if let Some(start_bench) = &start_bench_barrier { + // As the final barrier participant, this call to `wait()` unlocks all the bench threads + start_bench.wait(); + } + start_bench_barrier = None; + count += 1; let max_accounts_met = if let Some(max_accounts) = max_accounts { total_accounts_created >= max_accounts