Extract read-only cache stats (#32789)
* extract read-only cache stat * rename stats --------- Co-authored-by: HaoranYi <haoran.yi@solana.com>
This commit is contained in:
parent
c9f7cb5b7e
commit
d26e3ff22b
|
@ -26,6 +26,32 @@ struct ReadOnlyAccountCacheEntry {
|
|||
index: AtomicU32, // Index of the entry in the eviction queue.
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct ReadOnlyCacheStats {
|
||||
hits: AtomicU64,
|
||||
misses: AtomicU64,
|
||||
evicts: AtomicU64,
|
||||
load_us: AtomicU64,
|
||||
}
|
||||
|
||||
impl ReadOnlyCacheStats {
|
||||
fn reset(&self) {
|
||||
self.hits.store(0, Ordering::Relaxed);
|
||||
self.misses.store(0, Ordering::Relaxed);
|
||||
self.evicts.store(0, Ordering::Relaxed);
|
||||
self.load_us.store(0, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
fn get_and_reset_stats(&self) -> (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);
|
||||
|
||||
(hits, misses, evicts, load_us)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ReadOnlyAccountsCache {
|
||||
cache: DashMap<ReadOnlyCacheKey, ReadOnlyAccountCacheEntry>,
|
||||
|
@ -37,10 +63,9 @@ pub struct ReadOnlyAccountsCache {
|
|||
queue: Mutex<IndexList<ReadOnlyCacheKey>>,
|
||||
max_data_size: usize,
|
||||
data_size: AtomicUsize,
|
||||
hits: AtomicU64,
|
||||
misses: AtomicU64,
|
||||
evicts: AtomicU64,
|
||||
load_us: AtomicU64,
|
||||
|
||||
// Performance statistics
|
||||
stats: ReadOnlyCacheStats,
|
||||
}
|
||||
|
||||
impl ReadOnlyAccountsCache {
|
||||
|
@ -50,10 +75,7 @@ impl ReadOnlyAccountsCache {
|
|||
cache: DashMap::default(),
|
||||
queue: Mutex::<IndexList<ReadOnlyCacheKey>>::default(),
|
||||
data_size: AtomicUsize::default(),
|
||||
hits: AtomicU64::default(),
|
||||
misses: AtomicU64::default(),
|
||||
evicts: AtomicU64::default(),
|
||||
load_us: AtomicU64::default(),
|
||||
stats: ReadOnlyCacheStats::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,10 +85,7 @@ impl ReadOnlyAccountsCache {
|
|||
self.cache.clear();
|
||||
self.queue.lock().unwrap().clear();
|
||||
self.data_size.store(0, Ordering::Relaxed);
|
||||
self.hits.store(0, Ordering::Relaxed);
|
||||
self.misses.store(0, Ordering::Relaxed);
|
||||
self.evicts.store(0, Ordering::Relaxed);
|
||||
self.load_us.store(0, Ordering::Relaxed);
|
||||
self.stats.reset();
|
||||
}
|
||||
|
||||
/// true if pubkey is in cache at slot
|
||||
|
@ -78,7 +97,7 @@ impl ReadOnlyAccountsCache {
|
|||
let (account, load_us) = measure_us!({
|
||||
let key = (pubkey, slot);
|
||||
let Some(entry) = self.cache.get(&key) else {
|
||||
self.misses.fetch_add(1, Ordering::Relaxed);
|
||||
self.stats.misses.fetch_add(1, Ordering::Relaxed);
|
||||
return None;
|
||||
};
|
||||
// Move the entry to the end of the queue.
|
||||
|
@ -91,10 +110,10 @@ impl ReadOnlyAccountsCache {
|
|||
}
|
||||
let account = entry.account.clone();
|
||||
drop(entry);
|
||||
self.hits.fetch_add(1, Ordering::Relaxed);
|
||||
self.stats.hits.fetch_add(1, Ordering::Relaxed);
|
||||
Some(account)
|
||||
});
|
||||
self.load_us.fetch_add(load_us, Ordering::Relaxed);
|
||||
self.stats.load_us.fetch_add(load_us, Ordering::Relaxed);
|
||||
account
|
||||
}
|
||||
|
||||
|
@ -135,7 +154,7 @@ impl ReadOnlyAccountsCache {
|
|||
num_evicts += 1;
|
||||
self.remove(pubkey, slot);
|
||||
}
|
||||
self.evicts.fetch_add(num_evicts, Ordering::Relaxed);
|
||||
self.stats.evicts.fetch_add(num_evicts, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn remove(&self, pubkey: Pubkey, slot: Slot) -> Option<AccountSharedData> {
|
||||
|
@ -158,12 +177,7 @@ impl ReadOnlyAccountsCache {
|
|||
}
|
||||
|
||||
pub(crate) fn get_and_reset_stats(&self) -> (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);
|
||||
|
||||
(hits, misses, evicts, load_us)
|
||||
self.stats.get_and_reset_stats()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue