From f0d67d7f28eb4bccfab0745df5c89cad3073d65d Mon Sep 17 00:00:00 2001 From: Brooks Date: Thu, 25 Jan 2024 17:27:45 -0500 Subject: [PATCH] Adds hit/miss stats for cache hash data (#34954) --- accounts-db/src/accounts_db.rs | 23 +++++++++++++++++++++++ accounts-db/src/cache_hash_data_stats.rs | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index ded01efa8..b1103cb17 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -7151,6 +7151,29 @@ impl AccountsDb { }) .collect::>(); + // Calculate the hits and misses of the hash data files cache. + // This is outside of the parallel loop above so that we only need to + // update each atomic stat value once. + // There are approximately 173 items in the cache files list, + // so should be very fast to iterate and compute. + // (173 cache files == 432,000 slots / 2,5000 slots-per-cache-file) + let mut hits = 0; + let mut misses = 0; + for cache_file in &cache_files { + match cache_file { + ScanAccountStorageResult::CacheFileAlreadyExists(_) => hits += 1, + ScanAccountStorageResult::CacheFileNeedsToBeCreated(_) => misses += 1, + }; + } + cache_hash_data + .stats + .hits + .fetch_add(hits, Ordering::Relaxed); + cache_hash_data + .stats + .misses + .fetch_add(misses, Ordering::Relaxed); + // deletes the old files that will not be used before creating new ones cache_hash_data.delete_old_cache_files(); diff --git a/accounts-db/src/cache_hash_data_stats.rs b/accounts-db/src/cache_hash_data_stats.rs index f8d3364f8..ba134dc22 100644 --- a/accounts-db/src/cache_hash_data_stats.rs +++ b/accounts-db/src/cache_hash_data_stats.rs @@ -15,6 +15,10 @@ pub struct CacheHashDataStats { pub load_us: AtomicU64, pub read_us: AtomicU64, pub unused_cache_files: AtomicUsize, + /// the number of hash data files that were found in the cache and reused + pub hits: AtomicUsize, + /// the number of hash data files that were not found in the cache + pub misses: AtomicUsize, } impl CacheHashDataStats { @@ -69,6 +73,8 @@ impl CacheHashDataStats { self.unused_cache_files.load(Ordering::Relaxed), i64 ), + ("hits", self.hits.load(Ordering::Relaxed), i64), + ("misses", self.misses.load(Ordering::Relaxed), i64), ); } }