Skip to content

Commit 4a8b33b

Browse files
jeffwashingtondankelleher
authored andcommitted
bg threads wait until next expected event (solana-labs#20126)
1 parent 8eee2d7 commit 4a8b33b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

runtime/src/bucket_map_holder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,14 @@ impl<T: IndexValue> BucketMapHolder<T> {
159159
let flush = self.disk.is_some();
160160
loop {
161161
if self.all_buckets_flushed_at_current_age() {
162+
let wait = std::cmp::min(
163+
self.age_timer.remaining_until_next_interval(AGE_MS),
164+
self.stats.remaining_until_next_interval(),
165+
);
166+
162167
let mut m = Measure::start("wait");
163168
self.wait_dirty_or_aged
164-
.wait_timeout(Duration::from_millis(AGE_MS));
169+
.wait_timeout(Duration::from_millis(wait));
165170
m.stop();
166171
self.stats
167172
.bg_waiting_us

runtime/src/bucket_map_holder_stats.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use solana_sdk::timing::{timestamp, AtomicInterval};
44
use std::fmt::Debug;
55
use std::sync::atomic::{AtomicU64, AtomicU8, Ordering};
66

7+
// stats logged every 10 s
8+
const STATS_INTERVAL_MS: u64 = 10_000;
9+
710
#[derive(Debug, Default)]
811
pub struct BucketMapHolderStats {
912
pub get_mem_us: AtomicU64,
@@ -92,9 +95,13 @@ impl BucketMapHolderStats {
9295
}
9396
}
9497

98+
pub fn remaining_until_next_interval(&self) -> u64 {
99+
self.last_time
100+
.remaining_until_next_interval(STATS_INTERVAL_MS)
101+
}
102+
95103
pub fn report_stats<T: IndexValue>(&self, storage: &BucketMapHolder<T>) {
96-
// account index stats every 10 s
97-
if !self.last_time.should_update(10_000) {
104+
if !self.last_time.should_update(STATS_INTERVAL_MS) {
98105
return;
99106
}
100107

0 commit comments

Comments
 (0)