From e72887d3a1337409d00c37629f1302370b44c09a Mon Sep 17 00:00:00 2001 From: brooks Date: Wed, 17 Jan 2024 15:58:47 -0500 Subject: [PATCH] Bring up to date the concurrent accounts benches --- runtime/benches/accounts.rs | 53 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/runtime/benches/accounts.rs b/runtime/benches/accounts.rs index 7efc0a11ac0d75..bc8d4cde80ae09 100644 --- a/runtime/benches/accounts.rs +++ b/runtime/benches/accounts.rs @@ -20,7 +20,7 @@ use { }, solana_runtime::bank::*, solana_sdk::{ - account::{AccountSharedData, ReadableAccount}, + account::{Account, AccountSharedData, ReadableAccount}, genesis_config::{create_genesis_config, ClusterType}, hash::Hash, lamports::LamportsError, @@ -203,23 +203,29 @@ fn store_accounts_with_possible_contention( let accounts = Arc::new(Accounts::new(Arc::new(accounts_db))); let num_keys = 1000; let slot = 0; + + let pubkeys: Vec<_> = std::iter::repeat_with(solana_sdk::pubkey::new_rand) + .take(num_keys) + .collect(); + let accounts_data: Vec<_> = std::iter::repeat(Account { + lamports: 1, + ..Default::default() + }) + .take(num_keys) + .collect(); + let storable_accounts: Vec<_> = pubkeys.iter().zip(accounts_data.iter()).collect(); + accounts.store_accounts_cached((slot, storable_accounts.as_slice())); accounts.add_root(slot); - let pubkeys: Arc> = Arc::new( - (0..num_keys) - .map(|_| { - let pubkey = solana_sdk::pubkey::new_rand(); - let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); - accounts.store_slow_uncached(slot, &pubkey, &account); - pubkey - }) - .collect(), - ); + accounts + .accounts_db + .flush_accounts_cache_slot_for_tests(slot); - for _ in 0..num_readers { + let pubkeys = Arc::new(pubkeys); + for i in 0..num_readers { let accounts = accounts.clone(); let pubkeys = pubkeys.clone(); Builder::new() - .name("readers".to_string()) + .name(format!("reader{i:02}")) .spawn(move || { reader_f(&accounts, &pubkeys); }) @@ -227,21 +233,19 @@ fn store_accounts_with_possible_contention( } let num_new_keys = 1000; - let new_accounts: Vec<_> = (0..num_new_keys) - .map(|_| AccountSharedData::new(1, 0, AccountSharedData::default().owner())) - .collect(); bencher.iter(|| { - for account in &new_accounts { - // Write to a different slot than the one being read from. Because - // there's a new account pubkey being written to every time, will - // compete for the accounts index lock on every store - accounts.store_slow_uncached(slot + 1, &solana_sdk::pubkey::new_rand(), account); - } - }) + let new_pubkeys: Vec<_> = std::iter::repeat_with(solana_sdk::pubkey::new_rand) + .take(num_new_keys) + .collect(); + let new_storable_accounts: Vec<_> = new_pubkeys.iter().zip(accounts_data.iter()).collect(); + // Write to a different slot than the one being read from. Because + // there's a new account pubkey being written to every time, will + // compete for the accounts index lock on every store + accounts.store_accounts_cached((slot + 1, new_storable_accounts.as_slice())); + }); } #[bench] -#[ignore] fn bench_concurrent_read_write(bencher: &mut Bencher) { store_accounts_with_possible_contention( "concurrent_read_write", @@ -261,7 +265,6 @@ fn bench_concurrent_read_write(bencher: &mut Bencher) { } #[bench] -#[ignore] fn bench_concurrent_scan_write(bencher: &mut Bencher) { store_accounts_with_possible_contention("concurrent_scan_write", bencher, |accounts, _| loop { test::black_box(