Skip to content

Commit

Permalink
PrioritizationFeeCache: make update() never sleep on the sender chann…
Browse files Browse the repository at this point in the history
…el (#3813)

Avoid update() callers having to notify the service_loop() thread by
doing an explicit sleep instead of sleeping on channel.recv() when the
channel is empty. This avoids the case in which multiple replay/banking
threads call update() at the same time and end up... sleeping themselves
acquiring the mutex to notify the receiver.
  • Loading branch information
alessandrod authored Nov 27, 2024
1 parent 5c8cde0 commit 53af223
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions runtime/src/prioritization_fee_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{bank::Bank, prioritization_fee::*},
crossbeam_channel::{unbounded, Receiver, Sender},
crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError},
log::*,
solana_accounts_db::account_locks::validate_account_locks,
solana_measure::measure_us,
Expand All @@ -15,7 +15,8 @@ use {
atomic::{AtomicU64, Ordering},
Arc, RwLock,
},
thread::{Builder, JoinHandle},
thread::{sleep, Builder, JoinHandle},
time::Duration,
},
};

Expand Down Expand Up @@ -358,7 +359,18 @@ impl PrioritizationFeeCache {
// for a slot. The updates are tracked and finalized by bank_id.
let mut unfinalized = UnfinalizedPrioritizationFees::new();

for update in receiver.iter() {
loop {
let update = match receiver.try_recv() {
Ok(update) => update,
Err(TryRecvError::Empty) => {
sleep(Duration::from_millis(5));
continue;
}
Err(err @ TryRecvError::Disconnected) => {
info!("PrioritizationFeeCache::service_loop() is stopping because: {err}");
break;
}
};
match update {
CacheServiceUpdate::TransactionUpdate {
slot,
Expand Down

0 comments on commit 53af223

Please sign in to comment.