Skip to content

Commit

Permalink
Adds metrics for how long it takes to store into the accounts read cache
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Apr 5, 2024
1 parent e09541a commit c7707c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8229,6 +8229,7 @@ impl AccountsDb {
read_only_cache_misses,
read_only_cache_evicts,
read_only_cache_load_us,
read_only_cache_store_us,
read_only_cache_evict_us,
) = self.read_only_accounts_cache.get_and_reset_stats();
datapoint_info!(
Expand Down Expand Up @@ -8301,6 +8302,11 @@ impl AccountsDb {
read_only_cache_load_us,
i64
),
(
"read_only_accounts_cache_store_us",
read_only_cache_store_us,
i64
),
(
"read_only_accounts_cache_evict_us",
read_only_cache_evict_us,
Expand Down
14 changes: 10 additions & 4 deletions accounts-db/src/read_only_accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use {
dashmap::{mapref::entry::Entry, DashMap},
index_list::{Index, IndexList},
solana_measure::measure_us,
solana_measure::{measure::Measure, measure_us},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::Slot,
Expand Down Expand Up @@ -36,6 +36,7 @@ struct ReadOnlyCacheStats {
misses: AtomicU64,
evicts: AtomicU64,
load_us: AtomicU64,
store_us: AtomicU64,
evict_us: AtomicU64,
}

Expand All @@ -45,17 +46,19 @@ impl ReadOnlyCacheStats {
self.misses.store(0, Ordering::Relaxed);
self.evicts.store(0, Ordering::Relaxed);
self.load_us.store(0, Ordering::Relaxed);
self.store_us.store(0, Ordering::Relaxed);
self.evict_us.store(0, Ordering::Relaxed);
}

fn get_and_reset_stats(&self) -> (u64, u64, u64, u64, u64) {
fn get_and_reset_stats(&self) -> (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, evict_us)
(hits, misses, evicts, load_us, store_us, evict_us)
}
}

Expand Down Expand Up @@ -139,6 +142,7 @@ impl ReadOnlyAccountsCache {
}

pub(crate) fn store(&self, pubkey: Pubkey, slot: Slot, account: AccountSharedData) {
let measure_store = Measure::start("");
self.highest_slot_stored.fetch_max(slot, Ordering::Release);
let key = (pubkey, slot);
let account_size = self.account_size(&account);
Expand Down Expand Up @@ -174,8 +178,10 @@ impl ReadOnlyAccountsCache {
self.remove(pubkey, slot);
}
});
let store_us = measure_store.end_as_us();
self.stats.evicts.fetch_add(num_evicts, Ordering::Relaxed);
self.stats.evict_us.fetch_add(evict_us, Ordering::Relaxed);
self.stats.store_us.fetch_add(store_us, Ordering::Relaxed);
}

/// true if any pubkeys could have ever been stored into the cache at `slot`
Expand Down Expand Up @@ -214,7 +220,7 @@ impl ReadOnlyAccountsCache {
self.data_size.load(Ordering::Relaxed)
}

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

0 comments on commit c7707c5

Please sign in to comment.