Skip to content

Commit

Permalink
Adds stats for how often the read cache evictor wakes up (solana-labs…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 7, 2024
1 parent 9cefe0c commit 21aa128
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8281,6 +8281,8 @@ impl AccountsDb {
read_only_cache_load_us,
read_only_cache_store_us,
read_only_cache_evict_us,
read_only_cache_evictor_wakeup_count_all,
read_only_cache_evictor_wakeup_count_productive,
) = self.read_only_accounts_cache.get_and_reset_stats();
datapoint_info!(
"accounts_db_store_timings",
Expand Down Expand Up @@ -8362,6 +8364,16 @@ impl AccountsDb {
read_only_cache_evict_us,
i64
),
(
"read_only_accounts_cache_evictor_wakeup_count_all",
read_only_cache_evictor_wakeup_count_all,
i64
),
(
"read_only_accounts_cache_evictor_wakeup_count_productive",
read_only_cache_evictor_wakeup_count_productive,
i64
),
(
"calc_stored_meta_us",
self.stats.calc_stored_meta.swap(0, Ordering::Relaxed),
Expand Down
32 changes: 28 additions & 4 deletions accounts-db/src/read_only_accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct ReadOnlyCacheStats {
load_us: AtomicU64,
store_us: AtomicU64,
evict_us: AtomicU64,
evictor_wakeup_count_all: AtomicU64,
evictor_wakeup_count_productive: AtomicU64,
}

impl ReadOnlyCacheStats {
Expand All @@ -57,17 +59,33 @@ impl ReadOnlyCacheStats {
self.load_us.store(0, Ordering::Relaxed);
self.store_us.store(0, Ordering::Relaxed);
self.evict_us.store(0, Ordering::Relaxed);
self.evictor_wakeup_count_all.store(0, Ordering::Relaxed);
self.evictor_wakeup_count_productive
.store(0, Ordering::Relaxed);
}

fn get_and_reset_stats(&self) -> (u64, u64, u64, u64, u64, u64) {
fn get_and_reset_stats(&self) -> (u64, u64, u64, u64, u64, u64, u64, u64) {
let hits = self.hits.swap(0, Ordering::Relaxed);
let misses = self.misses.swap(0, Ordering::Relaxed);
let evicts = self.evicts.swap(0, Ordering::Relaxed);
let load_us = self.load_us.swap(0, Ordering::Relaxed);
let store_us = self.store_us.swap(0, Ordering::Relaxed);
let evict_us = self.evict_us.swap(0, Ordering::Relaxed);

(hits, misses, evicts, load_us, store_us, evict_us)
let evictor_wakeup_count_all = self.evictor_wakeup_count_all.swap(0, Ordering::Relaxed);
let evictor_wakeup_count_productive = self
.evictor_wakeup_count_productive
.swap(0, Ordering::Relaxed);

(
hits,
misses,
evicts,
load_us,
store_us,
evict_us,
evictor_wakeup_count_all,
evictor_wakeup_count_productive,
)
}
}

Expand Down Expand Up @@ -268,7 +286,7 @@ impl ReadOnlyAccountsCache {
self.data_size.load(Ordering::Relaxed)
}

pub(crate) fn get_and_reset_stats(&self) -> (u64, u64, u64, u64, u64, u64) {
pub(crate) fn get_and_reset_stats(&self) -> (u64, u64, u64, u64, u64, u64, u64, u64) {
self.stats.get_and_reset_stats()
}

Expand Down Expand Up @@ -305,6 +323,9 @@ impl ReadOnlyAccountsCache {
trace!("AccountsReadCacheEvictor is shutting down... {err}");
break;
};
stats
.evictor_wakeup_count_all
.fetch_add(1, Ordering::Relaxed);

// If a message was sent to the channel *while we were already evicting*, then
// when we loop around we'll find a message that we should evict again.
Expand All @@ -313,6 +334,9 @@ impl ReadOnlyAccountsCache {
if data_size.load(Ordering::Relaxed) <= max_data_size_hi {
continue;
}
stats
.evictor_wakeup_count_productive
.fetch_add(1, Ordering::Relaxed);

let (num_evicts, evict_us) =
measure_us!(Self::evict(max_data_size_lo, &data_size, &cache, &queue));
Expand Down

0 comments on commit 21aa128

Please sign in to comment.