Skip to content

Commit

Permalink
Adding bench_poh_recorder_record_transaction_index
Browse files Browse the repository at this point in the history
Adapted from test_poh_recorder_record_transaction_index

test bench_poh_recorder_record_transaction_index ... bench:  27,786,204 ns/iter (+/- 1,134,088)
  • Loading branch information
ksolana committed Aug 15, 2024
1 parent f46fda3 commit 44834b7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
93 changes: 91 additions & 2 deletions poh/benches/poh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ extern crate test;

use {
solana_entry::poh::Poh,
solana_poh::poh_service::DEFAULT_HASHES_PER_BATCH,
solana_sdk::hash::Hash,
solana_ledger::{
blockstore::Blockstore,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
get_tmp_ledger_path_auto_delete,
leader_schedule_cache::LeaderScheduleCache,
},
solana_perf::test_tx::test_tx,
solana_poh::{poh_recorder::PohRecorder, poh_service::DEFAULT_HASHES_PER_BATCH},
solana_runtime::bank::Bank,
solana_sdk::{
hash::{hash, Hash},
poh_config::PohConfig,
transaction::SanitizedTransaction,
},
std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
Expand Down Expand Up @@ -65,3 +77,80 @@ fn bench_poh_lock_time_per_batch(bencher: &mut Bencher) {
poh.hash(DEFAULT_HASHES_PER_BATCH);
})
}

#[bench]
fn bench_poh_recorder_record_transaction_index(bencher: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Blockstore::open(ledger_path.path()).expect("Expected to be able to open database ledger");
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
let prev_hash = bank.last_blockhash();

let (mut poh_recorder, _entry_receiver, _record_receiver) = PohRecorder::new(
0,
prev_hash,
bank.clone(),
Some((4, 4)),
bank.ticks_per_slot(),
Arc::new(blockstore),
&std::sync::Arc::new(LeaderScheduleCache::new_from_bank(&bank)),
&PohConfig::default(),
Arc::new(AtomicBool::default()),
);
let h1 = hash(b"hello Agave, hello Anza!");

poh_recorder.set_bank_with_transaction_index_for_test(bank.clone());
poh_recorder.tick();
let txs: [SanitizedTransaction; 7] = [
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
SanitizedTransaction::from_transaction_for_tests(test_tx()),
];

bencher.iter(|| {
let _record_result = poh_recorder
.record(
bank.slot(),
test::black_box(h1),
test::black_box(&txs)
.iter()
.map(|tx| tx.to_versioned_transaction())
.collect(),
)
.unwrap()
.unwrap();
});
poh_recorder.tick();
}

#[bench]
fn bench_poh_recorder_set_bank(bencher: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Blockstore::open(ledger_path.path()).expect("Expected to be able to open database ledger");
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2);
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
let prev_hash = bank.last_blockhash();

let (mut poh_recorder, _entry_receiver, _record_receiver) = PohRecorder::new(
0,
prev_hash,
bank.clone(),
Some((4, 4)),
bank.ticks_per_slot(),
Arc::new(blockstore),
&std::sync::Arc::new(LeaderScheduleCache::new_from_bank(&bank)),
&PohConfig::default(),
Arc::new(AtomicBool::default()),
);
bencher.iter(|| {
poh_recorder.set_bank_with_transaction_index_for_test(bank.clone());
poh_recorder.tick();
poh_recorder.clear_bank_for_test();
});
}
7 changes: 6 additions & 1 deletion poh/src/poh_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,16 @@ impl PohRecorder {
self.set_bank(BankWithScheduler::new_without_scheduler(bank), false)
}

#[cfg(test)]
#[cfg(feature = "dev-context-only-utils")]
pub fn set_bank_with_transaction_index_for_test(&mut self, bank: Arc<Bank>) {
self.set_bank(BankWithScheduler::new_without_scheduler(bank), true)
}

#[cfg(feature = "dev-context-only-utils")]
pub fn clear_bank_for_test(&mut self) {
self.clear_bank();
}

// Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height
// On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record
// occurs after the min_tick_height was generated
Expand Down

0 comments on commit 44834b7

Please sign in to comment.