Skip to content

Commit

Permalink
Wait for at least one account to have been created before starting th…
Browse files Browse the repository at this point in the history
…e account benchmarks (#3960)
  • Loading branch information
steveluscher authored Dec 9, 2024
1 parent be115c7 commit 1c2dc20
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use {
str::FromStr,
sync::{
atomic::{AtomicBool, AtomicU64, Ordering},
Arc,
Arc, Barrier,
},
thread::{sleep, Builder, JoinHandle},
time::{Duration, Instant},
Expand Down Expand Up @@ -508,6 +508,7 @@ fn run_rpc_bench_loop(
fn make_rpc_bench_threads(
rpc_benches: Vec<RpcBench>,
mint: &Option<Pubkey>,
start_bench_barrier: &Arc<Barrier>,
exit: &Arc<AtomicBool>,
client: &Arc<RpcClient>,
seed_tracker: &SeedTracker,
Expand All @@ -524,13 +525,15 @@ 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();
let mint = *mint;
Builder::new()
.name(format!("rpc-bench-{}", thread))
.spawn(move || {
start_bench.wait();
run_rpc_bench_loop(
rpc_bench,
thread,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c2dc20

Please sign in to comment.