From 014a92664559db52c41df6799b82fd636ceca7fd Mon Sep 17 00:00:00 2001 From: kirill lykov Date: Sat, 13 Aug 2022 13:01:25 +0200 Subject: [PATCH] Bench tps add nonce flag (#27030) * add durable nonce option * make blockhash thread optional * add nonce test to bench-tps --- bench-tps/src/bench.rs | 63 ++++++++++++++++++++++++++---------- bench-tps/src/cli.rs | 2 ++ bench-tps/src/main.rs | 11 +++++-- bench-tps/tests/bench_tps.rs | 24 ++++++++++++-- 4 files changed, 78 insertions(+), 22 deletions(-) diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index df34e619a6..33ff5bc51f 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -245,13 +245,20 @@ fn generate_chunked_transfers(client: Arc, config: Config, gen_keypairs: Vec) -> u64 +pub fn do_bench_tps( + client: Arc, + config: Config, + gen_keypairs: Vec, + nonce_keypairs: Option>, +) -> u64 where T: 'static + BenchTpsClient + Send + Sync + ?Sized, { @@ -331,6 +343,7 @@ where sustained, target_slots_per_epoch, use_randomized_compute_unit_price, + use_durable_nonce, .. } = config; @@ -338,7 +351,7 @@ where let chunk_generator = TransactionChunkGenerator::new( client.clone(), &gen_keypairs, - None, // TODO(klykov): to be added in the follow up PR + nonce_keypairs.as_ref(), tx_count, use_randomized_compute_unit_price, ); @@ -368,17 +381,22 @@ where let shared_tx_active_thread_count = Arc::new(AtomicIsize::new(0)); let total_tx_sent_count = Arc::new(AtomicUsize::new(0)); - let blockhash_thread = { + // if we use durable nonce, we don't need blockhash thread + let blockhash_thread = if !use_durable_nonce { let exit_signal = exit_signal.clone(); let blockhash = blockhash.clone(); let client = client.clone(); let id = id.pubkey(); - Builder::new() - .name("solana-blockhash-poller".to_string()) - .spawn(move || { - poll_blockhash(&exit_signal, &blockhash, &client, &id); - }) - .unwrap() + Some( + Builder::new() + .name("solana-blockhash-poller".to_string()) + .spawn(move || { + poll_blockhash(&exit_signal, &blockhash, &client, &id); + }) + .unwrap(), + ) + } else { + None }; let s_threads = create_sender_threads( @@ -403,6 +421,7 @@ where threads, duration, sustained, + use_durable_nonce, ); // Stop the sampling threads so it will collect the stats @@ -421,9 +440,15 @@ where } } - info!("Waiting for blockhash thread..."); - if let Err(err) = blockhash_thread.join() { - info!(" join() failed with: {:?}", err); + if let Some(blockhash_thread) = blockhash_thread { + info!("Waiting for blockhash thread..."); + if let Err(err) = blockhash_thread.join() { + info!(" join() failed with: {:?}", err); + } + } + + if let Some(nonce_keypairs) = nonce_keypairs { + withdraw_durable_nonce_accounts(client.clone(), &gen_keypairs, &nonce_keypairs); } let balance = client.get_balance(&id.pubkey()).unwrap_or(0); @@ -574,10 +599,14 @@ fn generate_txs( blockhash: &Arc>, chunk_generator: &mut TransactionChunkGenerator<'_, '_, T>, threads: usize, + use_durable_nonce: bool, ) { - let blockhash = blockhash.read().map(|x| *x).ok(); - - let transactions = chunk_generator.generate(blockhash.as_ref()); + let transactions = if use_durable_nonce { + chunk_generator.generate(None) + } else { + let blockhash = blockhash.read().map(|x| *x).ok(); + chunk_generator.generate(blockhash.as_ref()) + }; let sz = transactions.len() / threads; let chunks: Vec<_> = transactions.chunks(sz).collect(); @@ -933,7 +962,7 @@ mod tests { let keypairs = generate_and_fund_keypairs(client.clone(), &config.id, keypair_count, 20).unwrap(); - do_bench_tps(client, config, keypairs); + do_bench_tps(client, config, keypairs, None); } #[test] diff --git a/bench-tps/src/cli.rs b/bench-tps/src/cli.rs index 0fad3a37b3..a1b5c28329 100644 --- a/bench-tps/src/cli.rs +++ b/bench-tps/src/cli.rs @@ -55,6 +55,7 @@ pub struct Config { pub use_quic: bool, pub tpu_connection_pool_size: usize, pub use_randomized_compute_unit_price: bool, + pub use_durable_nonce: bool, } impl Default for Config { @@ -83,6 +84,7 @@ impl Default for Config { use_quic: DEFAULT_TPU_USE_QUIC, tpu_connection_pool_size: DEFAULT_TPU_CONNECTION_POOL_SIZE, use_randomized_compute_unit_price: false, + use_durable_nonce: false, } } } diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index 2894731a52..ab0fc099f3 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -8,7 +8,7 @@ use { bench_tps_client::BenchTpsClient, cli::{self, ExternalClientType}, keypairs::get_keypairs, - send_batch::generate_keypairs, + send_batch::{generate_durable_nonce_accounts, generate_keypairs}, }, solana_client::{ connection_cache::ConnectionCache, @@ -154,6 +154,7 @@ fn main() { use_quic, tpu_connection_pool_size, use_randomized_compute_unit_price, + use_durable_nonce, .. } = &cli_config; @@ -230,5 +231,11 @@ fn main() { client_ids_and_stake_file, *read_from_client_file, ); - do_bench_tps(client, cli_config, keypairs); + + let nonce_keypairs = if *use_durable_nonce { + Some(generate_durable_nonce_accounts(client.clone(), &keypairs)) + } else { + None + }; + do_bench_tps(client, cli_config, keypairs, nonce_keypairs); } diff --git a/bench-tps/tests/bench_tps.rs b/bench-tps/tests/bench_tps.rs index 6d1c32b47a..220980f9b0 100644 --- a/bench-tps/tests/bench_tps.rs +++ b/bench-tps/tests/bench_tps.rs @@ -1,9 +1,11 @@ #![allow(clippy::integer_arithmetic)] + use { serial_test::serial, solana_bench_tps::{ bench::{do_bench_tps, generate_and_fund_keypairs}, cli::Config, + send_batch::generate_durable_nonce_accounts, }, solana_client::{ connection_cache::ConnectionCache, @@ -76,7 +78,7 @@ fn test_bench_tps_local_cluster(config: Config) { ) .unwrap(); - let _total = do_bench_tps(client, config, keypairs); + let _total = do_bench_tps(client, config, keypairs, None); #[cfg(not(debug_assertions))] assert!(_total > 100); @@ -110,7 +112,7 @@ fn test_bench_tps_test_validator(config: Config) { .unwrap(), ); - let lamports_per_account = 100; + let lamports_per_account = 1000; let keypair_count = config.tx_count * config.keypair_multiplier; let keypairs = generate_and_fund_keypairs( @@ -120,8 +122,13 @@ fn test_bench_tps_test_validator(config: Config) { lamports_per_account, ) .unwrap(); + let nonce_keypairs = if config.use_durable_nonce { + Some(generate_durable_nonce_accounts(client.clone(), &keypairs)) + } else { + None + }; - let _total = do_bench_tps(client, config, keypairs); + let _total = do_bench_tps(client, config, keypairs, nonce_keypairs); #[cfg(not(debug_assertions))] assert!(_total > 100); @@ -146,3 +153,14 @@ fn test_bench_tps_tpu_client() { ..Config::default() }); } + +#[test] +#[serial] +fn test_bench_tps_tpu_client_nonce() { + test_bench_tps_test_validator(Config { + tx_count: 100, + duration: Duration::from_secs(10), + use_durable_nonce: true, + ..Config::default() + }); +}