solana/runtime/benches/prioritization_fee_cache.rs

114 lines
3.5 KiB
Rust
Raw Normal View History

#![feature(test)]
extern crate test;
use {
rand::{thread_rng, Rng},
solana_runtime::{
bank::Bank,
bank_forks::BankForks,
genesis_utils::{create_genesis_config, GenesisConfigInfo},
prioritization_fee_cache::*,
},
solana_sdk::{
compute_budget::ComputeBudgetInstruction,
message::Message,
pubkey::Pubkey,
system_instruction,
transaction::{SanitizedTransaction, Transaction},
},
std::sync::Arc,
test::Bencher,
};
const TRANSFER_TRANSACTION_COMPUTE_UNIT: u32 = 200;
fn build_sanitized_transaction(
compute_unit_price: u64,
signer_account: &Pubkey,
write_account: &Pubkey,
) -> SanitizedTransaction {
let transfer_lamports = 1;
let transaction = Transaction::new_unsigned(Message::new(
&[
system_instruction::transfer(signer_account, write_account, transfer_lamports),
ComputeBudgetInstruction::set_compute_unit_limit(TRANSFER_TRANSACTION_COMPUTE_UNIT),
ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price),
],
Some(signer_account),
));
SanitizedTransaction::try_from_legacy_transaction(transaction).unwrap()
}
#[bench]
#[ignore]
fn bench_process_transactions_single_slot(bencher: &mut Bencher) {
let prioritization_fee_cache = PrioritizationFeeCache::default();
let bank = Arc::new(Bank::default_for_tests());
// build test transactions
let transactions: Vec<_> = (0..5000)
.map(|n| {
let compute_unit_price = n % 7;
build_sanitized_transaction(
compute_unit_price,
&Pubkey::new_unique(),
&Pubkey::new_unique(),
)
})
.collect();
bencher.iter(|| {
prioritization_fee_cache.update(&bank, transactions.iter());
});
}
fn process_transactions_multiple_slots(banks: &[Arc<Bank>], num_slots: usize, num_threads: usize) {
let prioritization_fee_cache = Arc::new(PrioritizationFeeCache::default());
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build()
.unwrap();
// each threads updates a slot a batch of 50 transactions, for 100 times
for _ in 0..100 {
pool.install(|| {
let transactions: Vec<_> = (0..50)
.map(|n| {
let compute_unit_price = n % 7;
build_sanitized_transaction(
compute_unit_price,
&Pubkey::new_unique(),
&Pubkey::new_unique(),
)
})
.collect();
Bump rand to 0.8, rand_chacha to 0.3, getrandom to 0.2 (#32871) * sdk: Add concurrent support for rand 0.7 and 0.8 * Update rand, rand_chacha, and getrandom versions * Run command to replace `gen_range` Run `git grep -l gen_range | xargs sed -i'' -e 's/gen_range(\(\S*\), /gen_range(\1../' * sdk: Fix users of older `gen_range` * Replace `hash::new_rand` with `hash::new_with_thread_rng` Run: ``` git grep -l hash::new_rand | xargs sed -i'' -e 's/hash::new_rand([^)]*/hash::new_with_thread_rng(/' ``` * perf: Use `Keypair::new()` instead of `generate` * Use older rand version in zk-token-sdk * program-runtime: Inline random key generation * bloom: Fix clippy warnings in tests * streamer: Scope rng usage correctly * perf: Fix clippy warning * accounts-db: Map to char to generate a random string * Remove `from_secret_key_bytes`, it's just `keypair_from_seed` * ledger: Generate keypairs by hand * ed25519-tests: Use new rand * runtime: Use new rand in all tests * gossip: Clean up clippy and inline keypair generators * core: Inline keypair generation for tests * Push sbf lockfile change * sdk: Sort dependencies correctly * Remove `hash::new_with_thread_rng`, use `Hash::new_unique()` * Use Keypair::new where chacha isn't used * sdk: Fix build by marking rand 0.7 optional * Hardcode secret key length, add static assertion * Unify `getrandom` crate usage to fix linking errors * bloom: Fix tests that require a random hash * Remove some dependencies, try to unify others * Remove unnecessary uses of rand and rand_core * Update lockfiles * Add back some dependencies to reduce rebuilds * Increase max rebuilds from 14 to 15 * frozen-abi: Remove `getrandom` * Bump rebuilds to 17 * Remove getrandom from zk-token-proof
2023-08-21 10:11:21 -07:00
let index = thread_rng().gen_range(0..num_slots);
prioritization_fee_cache.update(&banks[index], transactions.iter());
})
}
}
#[bench]
#[ignore]
fn bench_process_transactions_multiple_slots(bencher: &mut Bencher) {
const NUM_SLOTS: usize = 5;
const NUM_THREADS: usize = 3;
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
let bank0 = Bank::new_for_benches(&genesis_config);
let bank_forks = BankForks::new_rw_arc(bank0);
let bank = bank_forks.read().unwrap().working_bank();
let collector = solana_sdk::pubkey::new_rand();
let banks = (1..=NUM_SLOTS)
.map(|n| Arc::new(Bank::new_from_parent(bank.clone(), &collector, n as u64)))
.collect::<Vec<_>>();
bencher.iter(|| {
process_transactions_multiple_slots(&banks, NUM_SLOTS, NUM_THREADS);
});
}