Skip to content

Commit

Permalink
convert benches/tests to be switchable
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Nov 27, 2024
1 parent 18f156b commit bda2cea
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 23 deletions.
14 changes: 13 additions & 1 deletion banking-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
solana_core::{
banking_stage::BankingStage,
banking_trace::{BankingPacketBatch, BankingTracer, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT},
validator::BlockProductionMethod,
validator::{BlockProductionMethod, TransactionStructure},
},
solana_gossip::cluster_info::{ClusterInfo, Node},
solana_ledger::{
Expand Down Expand Up @@ -288,6 +288,14 @@ fn main() {
.possible_values(BlockProductionMethod::cli_names())
.help(BlockProductionMethod::cli_message()),
)
.arg(
Arg::with_name("transaction_struct")
.long("transaction-structure")
.value_name("STRUCT")
.takes_value(true)
.possible_values(TransactionStructure::cli_names())
.help(TransactionStructure::cli_message()),
)
.arg(
Arg::new("num_banking_threads")
.long("num-banking-threads")
Expand Down Expand Up @@ -318,6 +326,9 @@ fn main() {
let block_production_method = matches
.value_of_t::<BlockProductionMethod>("block_production_method")
.unwrap_or_default();
let transaction_struct = matches
.value_of_t::<TransactionStructure>("transaction_struct")
.unwrap_or_default();
let num_banking_threads = matches
.value_of_t::<u32>("num_banking_threads")
.unwrap_or_else(|_| BankingStage::num_threads());
Expand Down Expand Up @@ -462,6 +473,7 @@ fn main() {
};
let banking_stage = BankingStage::new_num_threads(
block_production_method,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down
80 changes: 73 additions & 7 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(test)]

use {
solana_core::validator::BlockProductionMethod,
solana_core::validator::{BlockProductionMethod, TransactionStructure},
solana_vote_program::{vote_state::TowerSync, vote_transaction::new_tower_sync_transaction},
};

Expand Down Expand Up @@ -192,7 +192,12 @@ enum TransactionType {
ProgramsAndVotes,
}

fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
fn bench_banking(
bencher: &mut Bencher,
tx_type: TransactionType,
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
) {
solana_logger::setup();
let num_threads = BankingStage::num_threads() as usize;
// a multiple of packet chunk duplicates to avoid races
Expand Down Expand Up @@ -291,7 +296,8 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {
let cluster_info = Arc::new(cluster_info);
let (s, _r) = unbounded();
let _banking_stage = BankingStage::new(
BlockProductionMethod::CentralScheduler,
block_production_method,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down Expand Up @@ -368,22 +374,82 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) {

#[bench]
fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
bench_banking(bencher, TransactionType::Accounts);
bench_banking(
bencher,
TransactionType::Accounts,
BlockProductionMethod::CentralScheduler,
TransactionStructure::Sdk,
);
}

#[bench]
fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
bench_banking(bencher, TransactionType::Programs);
bench_banking(
bencher,
TransactionType::Programs,
BlockProductionMethod::CentralScheduler,
TransactionStructure::Sdk,
);
}

#[bench]
fn bench_banking_stage_multi_accounts_with_voting(bencher: &mut Bencher) {
bench_banking(bencher, TransactionType::AccountsAndVotes);
bench_banking(
bencher,
TransactionType::AccountsAndVotes,
BlockProductionMethod::CentralScheduler,
TransactionStructure::Sdk,
);
}

#[bench]
fn bench_banking_stage_multi_programs_with_voting(bencher: &mut Bencher) {
bench_banking(bencher, TransactionType::ProgramsAndVotes);
bench_banking(
bencher,
TransactionType::ProgramsAndVotes,
BlockProductionMethod::CentralScheduler,
TransactionStructure::Sdk,
);
}

#[bench]
fn bench_banking_stage_multi_accounts_view(bencher: &mut Bencher) {
bench_banking(
bencher,
TransactionType::Accounts,
BlockProductionMethod::CentralScheduler,
TransactionStructure::View,
);
}

#[bench]
fn bench_banking_stage_multi_programs_view(bencher: &mut Bencher) {
bench_banking(
bencher,
TransactionType::Programs,
BlockProductionMethod::CentralScheduler,
TransactionStructure::View,
);
}

#[bench]
fn bench_banking_stage_multi_accounts_with_voting_view(bencher: &mut Bencher) {
bench_banking(
bencher,
TransactionType::AccountsAndVotes,
BlockProductionMethod::CentralScheduler,
TransactionStructure::View,
);
}

#[bench]
fn bench_banking_stage_multi_programs_with_voting_view(bencher: &mut Bencher) {
bench_banking(
bencher,
TransactionType::ProgramsAndVotes,
BlockProductionMethod::CentralScheduler,
TransactionStructure::View,
);
}

fn simulate_process_entries(
Expand Down
6 changes: 5 additions & 1 deletion core/src/banking_simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
BankingPacketBatch, BankingTracer, ChannelLabel, TimedTracedEvent, TracedEvent,
TracedSender, TracerThread, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT, BASENAME,
},
validator::BlockProductionMethod,
validator::{BlockProductionMethod, TransactionStructure},
},
bincode::deserialize_from,
crossbeam_channel::{unbounded, Sender},
Expand Down Expand Up @@ -672,6 +672,7 @@ impl BankingSimulator {
bank_forks: Arc<RwLock<BankForks>>,
blockstore: Arc<Blockstore>,
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
) -> (SenderLoop, SimulatorLoop, SimulatorThreads) {
let parent_slot = self.parent_slot().unwrap();
let mut packet_batches_by_time = self.banking_trace_events.packet_batches_by_time;
Expand Down Expand Up @@ -802,6 +803,7 @@ impl BankingSimulator {
let prioritization_fee_cache = &Arc::new(PrioritizationFeeCache::new(0u64));
let banking_stage = BankingStage::new_num_threads(
block_production_method.clone(),
transaction_struct.clone(),
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down Expand Up @@ -889,12 +891,14 @@ impl BankingSimulator {
bank_forks: Arc<RwLock<BankForks>>,
blockstore: Arc<Blockstore>,
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
) -> Result<(), SimulateError> {
let (sender_loop, simulator_loop, simulator_threads) = self.prepare_simulation(
genesis_config,
bank_forks,
blockstore,
block_production_method,
transaction_struct,
);

sender_loop.log_starting();
Expand Down
40 changes: 29 additions & 11 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ impl BankingStage {
#[allow(clippy::too_many_arguments)]
pub fn new(
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
cluster_info: &impl LikeClusterInfo,
poh_recorder: &Arc<RwLock<PohRecorder>>,
non_vote_receiver: BankingPacketReceiver,
Expand All @@ -369,6 +370,7 @@ impl BankingStage {
) -> Self {
Self::new_num_threads(
block_production_method,
transaction_struct,
cluster_info,
poh_recorder,
non_vote_receiver,
Expand All @@ -388,6 +390,7 @@ impl BankingStage {
#[allow(clippy::too_many_arguments)]
pub fn new_num_threads(
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
cluster_info: &impl LikeClusterInfo,
poh_recorder: &Arc<RwLock<PohRecorder>>,
non_vote_receiver: BankingPacketReceiver,
Expand All @@ -404,7 +407,7 @@ impl BankingStage {
) -> Self {
match block_production_method {
BlockProductionMethod::CentralScheduler => Self::new_central_scheduler(
TransactionStructure::Sdk,
transaction_struct,
cluster_info,
poh_recorder,
non_vote_receiver,
Expand Down Expand Up @@ -920,6 +923,7 @@ mod tests {
sync::atomic::{AtomicBool, Ordering},
thread::sleep,
},
test_case::test_case,
};

pub(crate) fn new_test_cluster_info(keypair: Option<Arc<Keypair>>) -> (Node, ClusterInfo) {
Expand All @@ -938,8 +942,9 @@ mod tests {
.collect()
}

#[test]
fn test_banking_stage_shutdown1() {
#[test_case(TransactionStructure::Sdk)]
#[test_case(TransactionStructure::View)]
fn test_banking_stage_shutdown1(transaction_struct: TransactionStructure) {
let genesis_config = create_genesis_config(2).genesis_config;
let (bank, bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
let banking_tracer = BankingTracer::new_disabled();
Expand All @@ -961,6 +966,7 @@ mod tests {

let banking_stage = BankingStage::new(
BlockProductionMethod::CentralScheduler,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand All @@ -984,8 +990,9 @@ mod tests {
Blockstore::destroy(ledger_path.path()).unwrap();
}

#[test]
fn test_banking_stage_tick() {
#[test_case(TransactionStructure::Sdk)]
#[test_case(TransactionStructure::View)]
fn test_banking_stage_tick(transaction_struct: TransactionStructure) {
solana_logger::setup();
let GenesisConfigInfo {
mut genesis_config, ..
Expand Down Expand Up @@ -1017,6 +1024,7 @@ mod tests {

let banking_stage = BankingStage::new(
BlockProductionMethod::CentralScheduler,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down Expand Up @@ -1063,7 +1071,10 @@ mod tests {
with_vers.into_iter().map(|(b, _)| b).collect()
}

fn test_banking_stage_entries_only(block_production_method: BlockProductionMethod) {
fn test_banking_stage_entries_only(
block_production_method: BlockProductionMethod,
transaction_struct: TransactionStructure,
) {
solana_logger::setup();
let GenesisConfigInfo {
genesis_config,
Expand Down Expand Up @@ -1097,6 +1108,7 @@ mod tests {

let banking_stage = BankingStage::new(
block_production_method,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down Expand Up @@ -1190,9 +1202,13 @@ mod tests {
Blockstore::destroy(ledger_path.path()).unwrap();
}

#[test]
fn test_banking_stage_entries_only_central_scheduler() {
test_banking_stage_entries_only(BlockProductionMethod::CentralScheduler);
#[test_case(TransactionStructure::Sdk)]
#[test_case(TransactionStructure::View)]
fn test_banking_stage_entries_only_central_scheduler(transaction_struct: TransactionStructure) {
test_banking_stage_entries_only(
BlockProductionMethod::CentralScheduler,
transaction_struct,
);
}

#[test]
Expand Down Expand Up @@ -1419,8 +1435,9 @@ mod tests {
tick_producer.unwrap()
}

#[test]
fn test_unprocessed_transaction_storage_full_send() {
#[test_case(TransactionStructure::Sdk)]
#[test_case(TransactionStructure::View)]
fn test_unprocessed_transaction_storage_full_send(transaction_struct: TransactionStructure) {
solana_logger::setup();
let GenesisConfigInfo {
genesis_config,
Expand Down Expand Up @@ -1454,6 +1471,7 @@ mod tests {

let banking_stage = BankingStage::new(
BlockProductionMethod::CentralScheduler,
transaction_struct,
&cluster_info,
&poh_recorder,
non_vote_receiver,
Expand Down
3 changes: 2 additions & 1 deletion core/src/tpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
sigverify_stage::SigVerifyStage,
staked_nodes_updater_service::StakedNodesUpdaterService,
tpu_entry_notifier::TpuEntryNotifier,
validator::{BlockProductionMethod, GeneratorConfig},
validator::{BlockProductionMethod, GeneratorConfig, TransactionStructure},
},
bytes::Bytes,
crossbeam_channel::{unbounded, Receiver},
Expand Down Expand Up @@ -266,6 +266,7 @@ impl Tpu {

let banking_stage = BankingStage::new(
block_production_method,
TransactionStructure::Sdk, // TODO: add cli
cluster_info,
poh_recorder,
non_vote_receiver,
Expand Down
8 changes: 6 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use {
solana_core::{
banking_simulation::{BankingSimulator, BankingTraceEvents},
system_monitor_service::{SystemMonitorService, SystemMonitorStatsReportConfig},
validator::{BlockProductionMethod, BlockVerificationMethod},
validator::{BlockProductionMethod, BlockVerificationMethod, TransactionStructure},
},
solana_cost_model::{cost_model::CostModel, cost_tracker::CostTracker},
solana_feature_set::{self as feature_set, FeatureSet},
Expand Down Expand Up @@ -2515,14 +2515,18 @@ fn main() {
BlockProductionMethod
)
.unwrap_or_default();
let transaction_struct =
value_t!(arg_matches, "transaction_struct", TransactionStructure)
.unwrap_or_default();

info!("Using: block-production-method: {block_production_method}");
info!("Using: block-production-method: {block_production_method} transaction-structure: {transaction_struct}");

match simulator.start(
genesis_config,
bank_forks,
blockstore,
block_production_method,
transaction_struct,
) {
Ok(()) => println!("Ok"),
Err(error) => {
Expand Down

0 comments on commit bda2cea

Please sign in to comment.