Rename SamplePerformanceService thread for consistency (#35332)
- Rename thread - Add uniform service start/stop logs - Misc cleanup with variables / constants / exit flag check
This commit is contained in:
parent
7c48cbb7aa
commit
140818221c
|
@ -11,8 +11,8 @@ use {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SAMPLE_INTERVAL: u64 = 60;
|
const SAMPLE_INTERVAL: Duration = Duration::from_secs(60);
|
||||||
const SLEEP_INTERVAL: u64 = 500;
|
const SLEEP_INTERVAL: Duration = Duration::from_millis(500);
|
||||||
|
|
||||||
pub struct SamplePerformanceService {
|
pub struct SamplePerformanceService {
|
||||||
thread_hdl: JoinHandle<()>,
|
thread_hdl: JoinHandle<()>,
|
||||||
|
@ -26,34 +26,26 @@ impl SamplePerformanceService {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let bank_forks = bank_forks.clone();
|
let bank_forks = bank_forks.clone();
|
||||||
|
|
||||||
info!("Starting SamplePerformance service");
|
|
||||||
let thread_hdl = Builder::new()
|
let thread_hdl = Builder::new()
|
||||||
.name("sample-performance".to_string())
|
.name("solSamplePerf".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
|
info!("SamplePerformanceService has started");
|
||||||
Self::run(bank_forks, blockstore, exit);
|
Self::run(bank_forks, blockstore, exit);
|
||||||
|
info!("SamplePerformanceService has stopped");
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Self { thread_hdl }
|
Self { thread_hdl }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(
|
fn run(bank_forks: Arc<RwLock<BankForks>>, blockstore: Arc<Blockstore>, exit: Arc<AtomicBool>) {
|
||||||
bank_forks: Arc<RwLock<BankForks>>,
|
|
||||||
blockstore: Arc<Blockstore>,
|
|
||||||
exit: Arc<AtomicBool>,
|
|
||||||
) {
|
|
||||||
let mut snapshot = StatsSnapshot::from_forks(&bank_forks);
|
let mut snapshot = StatsSnapshot::from_forks(&bank_forks);
|
||||||
|
let mut last_sample_time = Instant::now();
|
||||||
|
|
||||||
let mut now = Instant::now();
|
while !exit.load(Ordering::Relaxed) {
|
||||||
loop {
|
let elapsed = last_sample_time.elapsed();
|
||||||
if exit.load(Ordering::Relaxed) {
|
if elapsed >= SAMPLE_INTERVAL {
|
||||||
break;
|
last_sample_time = Instant::now();
|
||||||
}
|
|
||||||
|
|
||||||
let elapsed = now.elapsed();
|
|
||||||
|
|
||||||
if elapsed.as_secs() >= SAMPLE_INTERVAL {
|
|
||||||
now = Instant::now();
|
|
||||||
let new_snapshot = StatsSnapshot::from_forks(&bank_forks);
|
let new_snapshot = StatsSnapshot::from_forks(&bank_forks);
|
||||||
|
|
||||||
let (num_transactions, num_non_vote_transactions, num_slots) =
|
let (num_transactions, num_non_vote_transactions, num_slots) =
|
||||||
|
@ -78,8 +70,7 @@ impl SamplePerformanceService {
|
||||||
error!("write_perf_sample failed: slot {:?} {:?}", highest_slot, e);
|
error!("write_perf_sample failed: slot {:?} {:?}", highest_slot, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sleep(SLEEP_INTERVAL);
|
||||||
sleep(Duration::from_millis(SLEEP_INTERVAL));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue