Skip to content

Commit

Permalink
minor sleeping efficiency improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Dec 3, 2024
1 parent 482e709 commit f87bd2f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions core/src/banking_stage/transaction_scheduler/receive_and_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,19 @@ impl ReceiveAndBuffer for TransactionViewReceiveAndBuffer {
let start = Instant::now();
let mut received_message = false;

// If not leader, do a blocking-receive initially. This lets the thread
// sleep when there is not work to do.
// TODO: Is it better to manually sleep instead, avoiding the locking
// overhead for wakers? But then risk not waking up when message
// received - as long as sleep is somewhat short, this should be
// fine.
if matches!(
decision,
BufferedPacketsDecision::Forward
| BufferedPacketsDecision::ForwardAndHold
| BufferedPacketsDecision::Hold
) {
// If not leader/unknown, do a blocking-receive initially. This lets
// the thread sleep until a message is received, or until the timeout.
// Additionally, only sleep if the container is empty.
if container.is_empty()
&& matches!(
decision,
BufferedPacketsDecision::Forward | BufferedPacketsDecision::ForwardAndHold
)
{
// TODO: Is it better to manually sleep instead, avoiding the locking
// overhead for wakers? But then risk not waking up when message
// received - as long as sleep is somewhat short, this should be
// fine.
match self.receiver.recv_timeout(TIMEOUT) {
Ok(packet_batch_message) => {
received_message = true;
Expand Down

0 comments on commit f87bd2f

Please sign in to comment.