Skip to content

Commit 9772f93

Browse files
committed
Wire unified scheduler into banking experimentally
1 parent d7e8a87 commit 9772f93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2266
-649
lines changed

Cargo.lock

+68-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,13 @@ curve25519-dalek = { version = "4.1.3", features = ["digest", "rand_core"] }
301301
dashmap = "5.5.3"
302302
derivation-path = { version = "0.2.0", default-features = false }
303303
derive-where = "1.2.7"
304+
derive_more = { version = "1.0.0", features = ["full"] }
304305
dialoguer = "0.10.4"
305306
digest = "0.10.7"
306307
dir-diff = "0.3.3"
307308
dirs-next = "2.0.0"
308309
dlopen2 = "0.5.0"
310+
dyn-clone = "1.0.17"
309311
eager = "0.1.0"
310312
ed25519-dalek = "=1.0.1"
311313
ed25519-dalek-bip32 = "0.2.0"
@@ -643,6 +645,7 @@ tokio-util = "0.7"
643645
toml = "0.8.12"
644646
tonic = "0.9.2"
645647
tonic-build = "0.9.2"
648+
trait-set = "0.3.0"
646649
trees = "0.4.2"
647650
tungstenite = "0.20.1"
648651
uriparse = "0.6.4"

banking-bench/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ license = { workspace = true }
99
edition = { workspace = true }
1010

1111
[dependencies]
12+
assert_matches = { workspace = true }
1213
clap = { version = "3.1.8", features = ["derive", "cargo"] }
1314
crossbeam-channel = { workspace = true }
1415
log = { workspace = true }
1516
rand = { workspace = true }
1617
rayon = { workspace = true }
1718
solana-client = { workspace = true }
18-
solana-core = { workspace = true }
19+
solana-core = { workspace = true, features = ["dev-context-only-utils"] }
1920
solana-gossip = { workspace = true }
2021
solana-ledger = { workspace = true }
2122
solana-logger = { workspace = true }
@@ -26,6 +27,7 @@ solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
2627
solana-sdk = { workspace = true }
2728
solana-streamer = { workspace = true }
2829
solana-tpu-client = { workspace = true }
30+
solana-unified-scheduler-pool = { workspace = true }
2931
solana-version = { workspace = true }
3032

3133
[features]

banking-bench/src/main.rs

+66-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#![allow(clippy::arithmetic_side_effects)]
22
use {
3+
assert_matches::assert_matches,
34
clap::{crate_description, crate_name, Arg, ArgEnum, Command},
45
crossbeam_channel::{unbounded, Receiver},
56
log::*,
67
rand::{thread_rng, Rng},
78
rayon::prelude::*,
89
solana_client::connection_cache::ConnectionCache,
910
solana_core::{
10-
banking_stage::BankingStage,
11-
banking_trace::{BankingPacketBatch, BankingTracer, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT},
11+
banking_stage::{update_bank_forks_and_poh_recorder_for_new_tpu_bank, BankingStage},
12+
banking_trace::{
13+
BankingPacketBatch, BankingTracer, Channels, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT,
14+
},
1215
validator::BlockProductionMethod,
1316
},
1417
solana_gossip::cluster_info::{ClusterInfo, Node},
@@ -29,13 +32,15 @@ use {
2932
hash::Hash,
3033
message::Message,
3134
pubkey::{self, Pubkey},
35+
scheduling::SchedulingMode,
3236
signature::{Keypair, Signature, Signer},
3337
system_instruction, system_transaction,
3438
timing::timestamp,
3539
transaction::Transaction,
3640
},
3741
solana_streamer::socket::SocketAddrSpace,
3842
solana_tpu_client::tpu_client::DEFAULT_TPU_CONNECTION_POOL_SIZE,
43+
solana_unified_scheduler_pool::{DefaultSchedulerPool, SupportedSchedulingMode},
3944
std::{
4045
sync::{atomic::Ordering, Arc, RwLock},
4146
thread::sleep,
@@ -347,7 +352,7 @@ fn main() {
347352
let (replay_vote_sender, _replay_vote_receiver) = unbounded();
348353
let bank0 = Bank::new_for_benches(&genesis_config);
349354
let bank_forks = BankForks::new_rw_arc(bank0);
350-
let mut bank = bank_forks.read().unwrap().working_bank();
355+
let mut bank = bank_forks.read().unwrap().working_bank_with_scheduler();
351356

352357
// set cost tracker limits to MAX so it will not filter out TXs
353358
bank.write_cost_tracker()
@@ -440,9 +445,36 @@ fn main() {
440445
BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT,
441446
)))
442447
.unwrap();
443-
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();
444-
let (tpu_vote_sender, tpu_vote_receiver) = banking_tracer.create_channel_tpu_vote();
445-
let (gossip_vote_sender, gossip_vote_receiver) = banking_tracer.create_channel_gossip_vote();
448+
let prioritization_fee_cache = Arc::new(PrioritizationFeeCache::new(0u64));
449+
let scheduler_pool = if matches!(
450+
block_production_method,
451+
BlockProductionMethod::UnifiedScheduler
452+
) {
453+
let pool = DefaultSchedulerPool::new(
454+
SupportedSchedulingMode::Either(SchedulingMode::BlockProduction),
455+
None,
456+
None,
457+
None,
458+
Some(replay_vote_sender.clone()),
459+
prioritization_fee_cache.clone(),
460+
poh_recorder.read().unwrap().new_recorder(),
461+
);
462+
bank_forks
463+
.write()
464+
.unwrap()
465+
.install_scheduler_pool(pool.clone());
466+
Some(pool)
467+
} else {
468+
None
469+
};
470+
let Channels {
471+
non_vote_sender,
472+
non_vote_receiver,
473+
tpu_vote_sender,
474+
tpu_vote_receiver,
475+
gossip_vote_sender,
476+
gossip_vote_receiver,
477+
} = banking_tracer.create_channels(scheduler_pool.as_ref());
446478
let cluster_info = {
447479
let keypair = Arc::new(Keypair::new());
448480
let node = Node::new_localhost_with_pubkey(&keypair.pubkey());
@@ -462,7 +494,7 @@ fn main() {
462494
)
463495
};
464496
let banking_stage = BankingStage::new_num_threads(
465-
block_production_method,
497+
block_production_method.clone(),
466498
&cluster_info,
467499
&poh_recorder,
468500
non_vote_receiver,
@@ -474,10 +506,23 @@ fn main() {
474506
None,
475507
Arc::new(connection_cache),
476508
bank_forks.clone(),
477-
&Arc::new(PrioritizationFeeCache::new(0u64)),
509+
&prioritization_fee_cache,
478510
false,
511+
scheduler_pool,
479512
);
480513

514+
// This bench processes transactions, starting from the very first bank, so special-casing is
515+
// needed for unified scheduler.
516+
if matches!(
517+
block_production_method,
518+
BlockProductionMethod::UnifiedScheduler
519+
) {
520+
bank = bank_forks
521+
.write()
522+
.unwrap()
523+
.reinstall_block_production_scheduler_into_working_genesis_bank();
524+
}
525+
481526
// This is so that the signal_receiver does not go out of scope after the closure.
482527
// If it is dropped before poh_service, then poh_service will error when
483528
// calling send() on the channel.
@@ -538,33 +583,31 @@ fn main() {
538583
tx_total_us += now.elapsed().as_micros() as u64;
539584

540585
let mut poh_time = Measure::start("poh_time");
541-
poh_recorder
586+
let cleared_bank = poh_recorder
542587
.write()
543588
.unwrap()
544589
.reset(bank.clone(), Some((bank.slot(), bank.slot() + 1)));
590+
assert_matches!(cleared_bank, None);
545591
poh_time.stop();
546592

547593
let mut new_bank_time = Measure::start("new_bank");
594+
if let Some((result, _timings)) = bank.wait_for_completed_scheduler() {
595+
assert_matches!(result, Ok(_));
596+
}
548597
let new_slot = bank.slot() + 1;
549-
let new_bank = Bank::new_from_parent(bank, &collector, new_slot);
598+
let new_bank = Bank::new_from_parent(bank.clone(), &collector, new_slot);
550599
new_bank_time.stop();
551600

552601
let mut insert_time = Measure::start("insert_time");
553-
bank_forks.write().unwrap().insert(new_bank);
554-
bank = bank_forks.read().unwrap().working_bank();
602+
update_bank_forks_and_poh_recorder_for_new_tpu_bank(
603+
&bank_forks,
604+
&poh_recorder,
605+
new_bank,
606+
false,
607+
);
608+
bank = bank_forks.read().unwrap().working_bank_with_scheduler();
555609
insert_time.stop();
556610

557-
// set cost tracker limits to MAX so it will not filter out TXs
558-
bank.write_cost_tracker()
559-
.unwrap()
560-
.set_limits(u64::MAX, u64::MAX, u64::MAX);
561-
562-
assert!(poh_recorder.read().unwrap().bank().is_none());
563-
poh_recorder
564-
.write()
565-
.unwrap()
566-
.set_bank_for_test(bank.clone());
567-
assert!(poh_recorder.read().unwrap().bank().is_some());
568611
debug!(
569612
"new_bank_time: {}us insert_time: {}us poh_time: {}us",
570613
new_bank_time.as_us(),

0 commit comments

Comments
 (0)