Skip to content

Commit

Permalink
Share the threadpool for tx execution and entry verifification (#216)
Browse files Browse the repository at this point in the history
Previously, entry verification had a dedicated threadpool used to verify
PoH hashes as well as some basic transaction verification via
Bank::verify_transaction(). It should also be noted that the entry
verification code provides logic to offload to a GPU if one is present.

Regardless of whether a GPU is present or not, some of the verification
must be done on a CPU. Moreso, the CPU verification of entries and
transaction execution are serial operations; entry verification finishes
first before moving onto transaction execution.

So, tx execution and entry verification are not competing for CPU cycles
at the same time and can use the same pool.

One exception to the above statement is that if someone is using the
feature to replay forks in parallel, then hypothetically, different
forks may end up competing for the same resources at the same time.
However, that is already true given that we had pools that were shared
between replay of multiple forks. So, this change doesn't really change
much for that case, but will reduce overhead in the single fork case
which is the vast majority of the time.
  • Loading branch information
steviez authored Mar 27, 2024
1 parent e70ff38 commit 10d0677
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 98 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ mod tests {
crate::banking_trace::{BankingPacketBatch, BankingTracer},
crossbeam_channel::{unbounded, Receiver},
itertools::Itertools,
solana_entry::entry::{Entry, EntrySlice},
solana_entry::entry::{self, Entry, EntrySlice},
solana_gossip::cluster_info::Node,
solana_ledger::{
blockstore::Blockstore,
Expand Down Expand Up @@ -941,7 +941,7 @@ mod tests {
.collect();
trace!("done");
assert_eq!(entries.len(), genesis_config.ticks_per_slot as usize);
assert!(entries.verify(&start_hash));
assert!(entries.verify(&start_hash, &entry::thread_pool_for_tests()));
assert_eq!(entries[entries.len() - 1].hash, bank.last_blockhash());
banking_stage.join().unwrap();
}
Expand Down Expand Up @@ -1060,7 +1060,7 @@ mod tests {
.map(|(_bank, (entry, _tick_height))| entry)
.collect();

assert!(entries.verify(&blockhash));
assert!(entries.verify(&blockhash, &entry::thread_pool_for_tests()));
if !entries.is_empty() {
blockhash = entries.last().unwrap().hash;
for entry in entries {
Expand Down
6 changes: 5 additions & 1 deletion entry/benches/entry_sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {

#[bench]
fn bench_gpusigverify(bencher: &mut Bencher) {
let thread_pool = entry::thread_pool_for_benches();
let entries = (0..131072)
.map(|_| {
let transaction = test_tx();
Expand Down Expand Up @@ -53,6 +54,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {
let res = entry::start_verify_transactions(
entries.clone(),
false,
&thread_pool,
recycler.clone(),
Arc::new(verify_transaction),
);
Expand All @@ -65,6 +67,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {

#[bench]
fn bench_cpusigverify(bencher: &mut Bencher) {
let thread_pool = entry::thread_pool_for_benches();
let entries = (0..131072)
.map(|_| {
let transaction = test_tx();
Expand All @@ -89,6 +92,7 @@ fn bench_cpusigverify(bencher: &mut Bencher) {
};

bencher.iter(|| {
let _ans = entry::verify_transactions(entries.clone(), Arc::new(verify_transaction));
let _ans =
entry::verify_transactions(entries.clone(), &thread_pool, Arc::new(verify_transaction));
})
}
Loading

0 comments on commit 10d0677

Please sign in to comment.