Skip to content

Commit

Permalink
Eagerly receive records in sleepy tick producer (solana-labs#21832)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Dec 14, 2021
1 parent 9da8264 commit e4f7af0
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions poh/src/poh_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
thread::{self, sleep, Builder, JoinHandle},
thread::{self, Builder, JoinHandle},
time::{Duration, Instant},
},
};
Expand Down Expand Up @@ -160,14 +160,20 @@ impl PohService {
poh_exit: &AtomicBool,
record_receiver: Receiver<Record>,
) {
let mut last_tick = Instant::now();
while !poh_exit.load(Ordering::Relaxed) {
let remaining_tick_time = poh_config
.target_tick_duration
.saturating_sub(last_tick.elapsed());
Self::read_record_receiver_and_process(
&poh_recorder,
&record_receiver,
Duration::from_millis(0),
remaining_tick_time,
);
sleep(poh_config.target_tick_duration);
poh_recorder.lock().unwrap().tick();
if remaining_tick_time.is_zero() {
last_tick = Instant::now();
poh_recorder.lock().unwrap().tick();
}
}
}

Expand Down Expand Up @@ -199,14 +205,23 @@ impl PohService {
record_receiver: Receiver<Record>,
) {
let mut warned = false;
for _ in 0..poh_config.target_tick_count.unwrap() {
let mut elapsed_ticks = 0;
let mut last_tick = Instant::now();
let num_ticks = poh_config.target_tick_count.unwrap();
while elapsed_ticks < num_ticks {
let remaining_tick_time = poh_config
.target_tick_duration
.saturating_sub(last_tick.elapsed());
Self::read_record_receiver_and_process(
&poh_recorder,
&record_receiver,
Duration::from_millis(0),
);
sleep(poh_config.target_tick_duration);
poh_recorder.lock().unwrap().tick();
if remaining_tick_time.is_zero() {
last_tick = Instant::now();
poh_recorder.lock().unwrap().tick();
elapsed_ticks += 1;
}
if poh_exit.load(Ordering::Relaxed) && !warned {
warned = true;
warn!("exit signal is ignored because PohService is scheduled to exit soon");
Expand Down Expand Up @@ -370,7 +385,7 @@ mod tests {
solana_sdk::{
clock, hash::hash, pubkey::Pubkey, timing, transaction::VersionedTransaction,
},
std::time::Duration,
std::{thread::sleep, time::Duration},
};

#[test]
Expand Down

0 comments on commit e4f7af0

Please sign in to comment.