bg threads wait until next expected event (#20126)

This commit is contained in:
Jeff Washington (jwash) 2021-09-24 16:00:41 -05:00 committed by GitHub
parent 3dfbd95ddc
commit c6d189dac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -159,9 +159,14 @@ impl<T: IndexValue> BucketMapHolder<T> {
let flush = self.disk.is_some();
loop {
if self.all_buckets_flushed_at_current_age() {
let wait = std::cmp::min(
self.age_timer.remaining_until_next_interval(AGE_MS),
self.stats.remaining_until_next_interval(),
);
let mut m = Measure::start("wait");
self.wait_dirty_or_aged
.wait_timeout(Duration::from_millis(AGE_MS));
.wait_timeout(Duration::from_millis(wait));
m.stop();
self.stats
.bg_waiting_us

View File

@ -4,6 +4,9 @@ use solana_sdk::timing::{timestamp, AtomicInterval};
use std::fmt::Debug;
use std::sync::atomic::{AtomicU64, AtomicU8, Ordering};
// stats logged every 10 s
const STATS_INTERVAL_MS: u64 = 10_000;
#[derive(Debug, Default)]
pub struct BucketMapHolderStats {
pub get_mem_us: AtomicU64,
@ -92,9 +95,13 @@ impl BucketMapHolderStats {
}
}
pub fn remaining_until_next_interval(&self) -> u64 {
self.last_time
.remaining_until_next_interval(STATS_INTERVAL_MS)
}
pub fn report_stats<T: IndexValue>(&self, storage: &BucketMapHolder<T>) {
// account index stats every 10 s
if !self.last_time.should_update(10_000) {
if !self.last_time.should_update(STATS_INTERVAL_MS) {
return;
}