Add bench test for voting threads (#28031)
This commit is contained in:
parent
a89010cc89
commit
84acef007c
|
@ -37,6 +37,9 @@ use {
|
||||||
},
|
},
|
||||||
solana_streamer::socket::SocketAddrSpace,
|
solana_streamer::socket::SocketAddrSpace,
|
||||||
solana_tpu_client::connection_cache::ConnectionCache,
|
solana_tpu_client::connection_cache::ConnectionCache,
|
||||||
|
solana_vote_program::{
|
||||||
|
vote_state::VoteStateUpdate, vote_transaction::new_vote_state_update_transaction,
|
||||||
|
},
|
||||||
std::{
|
std::{
|
||||||
sync::{atomic::Ordering, Arc, RwLock},
|
sync::{atomic::Ordering, Arc, RwLock},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
@ -142,9 +145,37 @@ fn make_programs_txs(txes: usize, hash: Hash) -> Vec<Transaction> {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_vote_txs(txes: usize) -> Vec<Transaction> {
|
||||||
|
// 1000 voters
|
||||||
|
let num_voters = 1000;
|
||||||
|
let (keypairs, vote_keypairs): (Vec<_>, Vec<_>) = (0..num_voters)
|
||||||
|
.map(|_| (Keypair::new(), Keypair::new()))
|
||||||
|
.unzip();
|
||||||
|
(0..txes)
|
||||||
|
.map(|i| {
|
||||||
|
// Quarter of the votes should be filtered out
|
||||||
|
let vote = if i % 4 == 0 {
|
||||||
|
VoteStateUpdate::from(vec![(2, 1)])
|
||||||
|
} else {
|
||||||
|
VoteStateUpdate::from(vec![(i as u64, 1)])
|
||||||
|
};
|
||||||
|
new_vote_state_update_transaction(
|
||||||
|
vote,
|
||||||
|
Hash::new_unique(),
|
||||||
|
&keypairs[i % num_voters],
|
||||||
|
&vote_keypairs[i % num_voters],
|
||||||
|
&vote_keypairs[i % num_voters],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
enum TransactionType {
|
enum TransactionType {
|
||||||
Accounts,
|
Accounts,
|
||||||
Programs,
|
Programs,
|
||||||
|
AccountsAndVotes,
|
||||||
|
ProgramsAndVotes,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
|
@ -182,8 +213,18 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
debug!("threads: {} txs: {}", num_threads, txes);
|
debug!("threads: {} txs: {}", num_threads, txes);
|
||||||
|
|
||||||
let transactions = match tx_type {
|
let transactions = match tx_type {
|
||||||
TransactionType::Accounts => make_accounts_txs(txes, &mint_keypair, genesis_config.hash()),
|
TransactionType::Accounts | TransactionType::AccountsAndVotes => {
|
||||||
TransactionType::Programs => make_programs_txs(txes, genesis_config.hash()),
|
make_accounts_txs(txes, &mint_keypair, genesis_config.hash())
|
||||||
|
}
|
||||||
|
TransactionType::Programs | TransactionType::ProgramsAndVotes => {
|
||||||
|
make_programs_txs(txes, genesis_config.hash())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let vote_txs = match tx_type {
|
||||||
|
TransactionType::AccountsAndVotes | TransactionType::ProgramsAndVotes => {
|
||||||
|
Some(make_vote_txs(txes))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// fund all the accounts
|
// fund all the accounts
|
||||||
|
@ -210,6 +251,16 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
}
|
}
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
let verified: Vec<_> = to_packet_batches(&transactions, PACKETS_PER_BATCH);
|
let verified: Vec<_> = to_packet_batches(&transactions, PACKETS_PER_BATCH);
|
||||||
|
let vote_packets = vote_txs.map(|vote_txs| {
|
||||||
|
let mut packet_batches = to_packet_batches(&vote_txs, PACKETS_PER_BATCH);
|
||||||
|
for batch in packet_batches.iter_mut() {
|
||||||
|
for packet in batch.iter_mut() {
|
||||||
|
packet.meta.set_simple_vote(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packet_batches
|
||||||
|
});
|
||||||
|
|
||||||
let ledger_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path!();
|
||||||
{
|
{
|
||||||
let blockstore = Arc::new(
|
let blockstore = Arc::new(
|
||||||
|
@ -250,7 +301,14 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
bencher.iter(move || {
|
bencher.iter(move || {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut sent = 0;
|
let mut sent = 0;
|
||||||
|
if let Some(vote_packets) = &vote_packets {
|
||||||
|
tpu_vote_sender
|
||||||
|
.send((vote_packets[start..start + chunk_len].to_vec(), None))
|
||||||
|
.unwrap();
|
||||||
|
vote_sender
|
||||||
|
.send((vote_packets[start..start + chunk_len].to_vec(), None))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
for v in verified[start..start + chunk_len].chunks(chunk_len / num_threads) {
|
for v in verified[start..start + chunk_len].chunks(chunk_len / num_threads) {
|
||||||
debug!(
|
debug!(
|
||||||
"sending... {}..{} {} v.len: {}",
|
"sending... {}..{} {} v.len: {}",
|
||||||
|
@ -264,6 +322,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
}
|
}
|
||||||
verified_sender.send((v.to_vec(), None)).unwrap();
|
verified_sender.send((v.to_vec(), None)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
check_txs(&signal_receiver2, txes / CHUNKS);
|
check_txs(&signal_receiver2, txes / CHUNKS);
|
||||||
|
|
||||||
// This signature clear may not actually clear the signatures
|
// This signature clear may not actually clear the signatures
|
||||||
|
@ -279,8 +338,6 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
|
||||||
start += chunk_len;
|
start += chunk_len;
|
||||||
start %= verified.len();
|
start %= verified.len();
|
||||||
});
|
});
|
||||||
drop(tpu_vote_sender);
|
|
||||||
drop(vote_sender);
|
|
||||||
exit.store(true, Ordering::Relaxed);
|
exit.store(true, Ordering::Relaxed);
|
||||||
poh_service.join().unwrap();
|
poh_service.join().unwrap();
|
||||||
}
|
}
|
||||||
|
@ -297,6 +354,16 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
bench_banking(bencher, TransactionType::Programs);
|
bench_banking(bencher, TransactionType::Programs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_banking_stage_multi_accounts_with_voting(bencher: &mut Bencher) {
|
||||||
|
bench_banking(bencher, TransactionType::AccountsAndVotes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_banking_stage_multi_programs_with_voting(bencher: &mut Bencher) {
|
||||||
|
bench_banking(bencher, TransactionType::ProgramsAndVotes);
|
||||||
|
}
|
||||||
|
|
||||||
fn simulate_process_entries(
|
fn simulate_process_entries(
|
||||||
randomize_txs: bool,
|
randomize_txs: bool,
|
||||||
mint_keypair: &Keypair,
|
mint_keypair: &Keypair,
|
||||||
|
|
|
@ -169,6 +169,11 @@ impl Meta {
|
||||||
self.flags.set(PacketFlags::TRACER_PACKET, is_tracer);
|
self.flags.set(PacketFlags::TRACER_PACKET, is_tracer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_simple_vote(&mut self, is_simple_vote: bool) {
|
||||||
|
self.flags.set(PacketFlags::SIMPLE_VOTE_TX, is_simple_vote);
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn forwarded(&self) -> bool {
|
pub fn forwarded(&self) -> bool {
|
||||||
self.flags.contains(PacketFlags::FORWARDED)
|
self.flags.contains(PacketFlags::FORWARDED)
|
||||||
|
|
Loading…
Reference in New Issue