From 133314e58c5c25f6a4b42e11be1f3bbe53f8eb8f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 9 Jan 2022 06:06:35 +0000 Subject: [PATCH] bank: fix executor cache metrics (#22396) (cherry picked from commit 3b4aad9df17639e25d8c77a700bb45c79649fba9) Co-authored-by: Trent Nelson --- runtime/src/bank.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 5944684287..dce23aa559 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -252,24 +252,32 @@ mod executor_cache { #[derive(Debug, Default)] pub struct Stats { - pub hits: u64, - pub misses: u64, + pub hits: AtomicU64, + pub misses: AtomicU64, pub evictions: HashMap, + pub insertions: AtomicU64, + pub replacements: AtomicU64, } impl Stats { pub fn submit(&self, slot: Slot) { + let hits = self.hits.load(Relaxed); + let misses = self.misses.load(Relaxed); + let insertions = self.insertions.load(Relaxed); + let replacements = self.replacements.load(Relaxed); let evictions: u64 = self.evictions.values().sum(); datapoint_info!( "bank-executor-cache-stats", ("slot", slot, i64), - ("hits", self.hits, i64), - ("misses", self.misses, i64), + ("hits", hits, i64), + ("misses", misses, i64), ("evictions", evictions, i64), + ("insertions", insertions, i64), + ("replacements", replacements, i64), ); debug!( - "Executor Cache Stats -- Hits: {}, Misses: {}, Evictions: {}", - self.hits, self.misses, evictions + "Executor Cache Stats -- Hits: {}, Misses: {}, Evictions: {}, Insertions: {}, Replacements: {}", + hits, misses, evictions, insertions, replacements, ); if log_enabled!(log::Level::Trace) && !self.evictions.is_empty() { let mut evictions = self.evictions.iter().collect::>(); @@ -381,10 +389,14 @@ impl CachedExecutors { } fn get(&self, pubkey: &Pubkey) -> Option> { - self.executors.get(pubkey).map(|entry| { + if let Some(entry) = self.executors.get(pubkey) { + self.stats.hits.fetch_add(1, Relaxed); entry.epoch_count.fetch_add(1, Relaxed); - entry.executor.clone() - }) + Some(entry.executor.clone()) + } else { + self.stats.misses.fetch_add(1, Relaxed); + None + } } fn put(&mut self, executors: &[(&Pubkey, Arc)]) { @@ -392,12 +404,12 @@ impl CachedExecutors { .iter() .filter_map(|(key, executor)| { if let Some(mut entry) = self.executors.remove(key) { - saturating_add_assign!(self.stats.hits, 1); + self.stats.replacements.fetch_add(1, Relaxed); entry.executor = executor.clone(); let _ = self.executors.insert(**key, entry); None } else { - saturating_add_assign!(self.stats.misses, 1); + self.stats.insertions.fetch_add(1, Relaxed); Some((*key, executor)) } })