Adds hit/miss stats for cache hash data (#34954)

This commit is contained in:
Brooks 2024-01-25 17:27:45 -05:00 committed by GitHub
parent 9e09524595
commit f0d67d7f28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -7151,6 +7151,29 @@ impl AccountsDb {
})
.collect::<Vec<_>>();
// 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();

View File

@ -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),
);
}
}