diff --git a/Cargo.lock b/Cargo.lock index a8836adf757915..f1c06592e86c3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6613,6 +6613,7 @@ dependencies = [ "solana-logger", "solana-measure", "solana-perf", + "solana-rayon-threadlimit", "solana-sdk", "solana-version", ] diff --git a/entry/benches/entry_sigverify.rs b/entry/benches/entry_sigverify.rs index b3a1b7b5cdb3e6..09adeb6cfd831a 100644 --- a/entry/benches/entry_sigverify.rs +++ b/entry/benches/entry_sigverify.rs @@ -16,6 +16,7 @@ use { #[bench] fn bench_gpusigverify(bencher: &mut Bencher) { + let thread_pool = entry::thread_pool_for_benches(); let entries = (0..131072) .map(|_| { let transaction = test_tx(); @@ -53,6 +54,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) { let res = entry::start_verify_transactions( entries.clone(), false, + &thread_pool, recycler.clone(), Arc::new(verify_transaction), ); @@ -65,6 +67,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) { #[bench] fn bench_cpusigverify(bencher: &mut Bencher) { + let thread_pool = entry::thread_pool_for_benches(); let entries = (0..131072) .map(|_| { let transaction = test_tx(); @@ -89,6 +92,7 @@ fn bench_cpusigverify(bencher: &mut Bencher) { }; bencher.iter(|| { - let _ans = entry::verify_transactions(entries.clone(), Arc::new(verify_transaction)); + let _ans = + entry::verify_transactions(entries.clone(), &thread_pool, Arc::new(verify_transaction)); }) } diff --git a/entry/src/entry.rs b/entry/src/entry.rs index 6160f0042962ec..3883462de672ac 100644 --- a/entry/src/entry.rs +++ b/entry/src/entry.rs @@ -20,6 +20,7 @@ use { recycler::Recycler, sigverify, }, + solana_rayon_threadlimit::get_max_thread_count, solana_sdk::{ hash::Hash, packet::Meta, @@ -961,6 +962,14 @@ pub fn entry_thread_pool_for_tests() -> ThreadPool { .expect("new rayon threadpool") } +pub fn thread_pool_for_benches() -> ThreadPool { + rayon::ThreadPoolBuilder::new() + .num_threads(get_max_thread_count()) + .thread_name(|i| format!("solEntryBnch{i:02}")) + .build() + .expect("new rayon threadpool") +} + #[cfg(test)] mod tests { use { diff --git a/poh-bench/Cargo.toml b/poh-bench/Cargo.toml index fb44c0cb81d966..8cd3979b17c79b 100644 --- a/poh-bench/Cargo.toml +++ b/poh-bench/Cargo.toml @@ -17,6 +17,7 @@ solana-entry = { workspace = true } solana-logger = { workspace = true } solana-measure = { workspace = true } solana-perf = { workspace = true } +solana-rayon-threadlimit = { workspace = true } solana-sdk = { workspace = true } solana-version = { workspace = true } diff --git a/poh-bench/src/main.rs b/poh-bench/src/main.rs index d835bac05a3ff9..941d581a825b73 100644 --- a/poh-bench/src/main.rs +++ b/poh-bench/src/main.rs @@ -7,6 +7,7 @@ use { clap::{crate_description, crate_name, Arg, Command}, solana_measure::measure::Measure, solana_perf::perf_libs, + solana_rayon_threadlimit::get_max_thread_count, solana_sdk::hash::hash, }; @@ -73,6 +74,14 @@ fn main() { let start_hash = hash(&[1, 2, 3, 4]); let ticks = create_ticks(max_num_entries, hashes_per_tick, start_hash); let mut num_entries = start_num_entries as usize; + let num_threads = matches + .value_of_t("num_threads") + .unwrap_or(get_max_thread_count()); + let thread_pool = rayon::ThreadPoolBuilder::new() + .num_threads(num_threads) + .thread_name(|i| format!("solPohBench{i:02}")) + .build() + .expect("new rayon threadpool"); if matches.is_present("cuda") { perf_libs::init_cuda(); } @@ -81,8 +90,8 @@ fn main() { let mut time = Measure::start("time"); for _ in 0..iterations { assert!(ticks[..num_entries] - .verify_cpu_generic(&start_hash) - .finish_verify()); + .verify_cpu_generic(&start_hash, &thread_pool) + .finish_verify(&thread_pool)); } time.stop(); println!( @@ -100,8 +109,8 @@ fn main() { let mut time = Measure::start("time"); for _ in 0..iterations { assert!(ticks[..num_entries] - .verify_cpu_x86_simd(&start_hash, 8) - .finish_verify()); + .verify_cpu_x86_simd(&start_hash, 8, &thread_pool) + .finish_verify(&thread_pool)); } time.stop(); println!( @@ -115,8 +124,8 @@ fn main() { let mut time = Measure::start("time"); for _ in 0..iterations { assert!(ticks[..num_entries] - .verify_cpu_x86_simd(&start_hash, 16) - .finish_verify()); + .verify_cpu_x86_simd(&start_hash, 16, &thread_pool) + .finish_verify(&thread_pool)); } time.stop(); println!( @@ -132,8 +141,8 @@ fn main() { let recyclers = VerifyRecyclers::default(); for _ in 0..iterations { assert!(ticks[..num_entries] - .start_verify(&start_hash, recyclers.clone()) - .finish_verify()); + .start_verify(&start_hash, &thread_pool, recyclers.clone()) + .finish_verify(&thread_pool)); } time.stop(); println!( diff --git a/poh/benches/poh_verify.rs b/poh/benches/poh_verify.rs index 47f31860c38d9c..cd33cdae43ef8d 100644 --- a/poh/benches/poh_verify.rs +++ b/poh/benches/poh_verify.rs @@ -2,7 +2,7 @@ extern crate test; use { - solana_entry::entry::{next_entry_mut, Entry, EntrySlice}, + solana_entry::entry::{self, next_entry_mut, Entry, EntrySlice}, solana_sdk::{ hash::{hash, Hash}, signature::{Keypair, Signer}, @@ -17,6 +17,8 @@ const NUM_ENTRIES: usize = 800; #[bench] fn bench_poh_verify_ticks(bencher: &mut Bencher) { solana_logger::setup(); + let thread_pool = entry::thread_pool_for_benches(); + let zero = Hash::default(); let start_hash = hash(zero.as_ref()); let mut cur_hash = start_hash; @@ -27,12 +29,14 @@ fn bench_poh_verify_ticks(bencher: &mut Bencher) { } bencher.iter(|| { - assert!(ticks.verify(&start_hash)); + assert!(ticks.verify(&start_hash, &thread_pool)); }) } #[bench] fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) { + let thread_pool = entry::thread_pool_for_benches(); + let zero = Hash::default(); let start_hash = hash(zero.as_ref()); let mut cur_hash = start_hash; @@ -47,6 +51,6 @@ fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) { } bencher.iter(|| { - assert!(ticks.verify(&start_hash)); + assert!(ticks.verify(&start_hash, &thread_pool)); }) }