Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

More metrics for LoadedPrograms cache #31735

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub struct Stats {
pub insertions: AtomicU64,
pub replacements: AtomicU64,
pub one_hit_wonders: AtomicU64,
pub prunes: AtomicU64,
pub expired: AtomicU64,
pub empty_entries: AtomicU64,
}

impl Stats {
Expand All @@ -128,6 +131,9 @@ impl Stats {
let replacements = self.replacements.load(Ordering::Relaxed);
let one_hit_wonders = self.one_hit_wonders.load(Ordering::Relaxed);
let evictions: u64 = self.evictions.values().sum();
let prunes = self.prunes.load(Ordering::Relaxed);
let expired = self.expired.load(Ordering::Relaxed);
let empty_entries = self.empty_entries.load(Ordering::Relaxed);
datapoint_info!(
"loaded-programs-cache-stats",
("slot", slot, i64),
Expand All @@ -137,10 +143,13 @@ impl Stats {
("insertions", insertions, i64),
("replacements", replacements, i64),
("one_hit_wonders", one_hit_wonders, i64),
("prunes", prunes, i64),
("evict_expired", expired, i64),
("evict_empty_entries", empty_entries, i64),
);
debug!(
"Loaded Programs Cache Stats -- Hits: {}, Misses: {}, Evictions: {}, Insertions: {}, Replacements: {}, One-Hit-Wonders: {}",
hits, misses, evictions, insertions, replacements, one_hit_wonders,
"Loaded Programs Cache Stats -- Hits: {}, Misses: {}, Evictions: {}, Insertions: {}, Replacements: {}, One-Hit-Wonders: {}, Prunes: {}, Expired: {}, Empty: {}",
hits, misses, evictions, insertions, replacements, one_hit_wonders, prunes, expired, empty_entries
);
if log_enabled!(log::Level::Trace) && !self.evictions.is_empty() {
let mut evictions = self.evictions.iter().collect::<Vec<_>>();
Expand Down Expand Up @@ -479,6 +488,7 @@ impl LoadedPrograms {
first_ancestor_found = true;
first_ancestor_found
} else {
self.stats.prunes.fetch_add(1, Ordering::Relaxed);
false
}
})
Expand Down Expand Up @@ -635,7 +645,14 @@ impl LoadedPrograms {
entry.retain(|program| {
program
.maybe_expiration_slot
.map(|expiration| expiration > current_slot)
.map(|expiration| {
if expiration > current_slot {
true
} else {
self.stats.expired.fetch_add(1, Ordering::Relaxed);
false
}
})
.unwrap_or(true)
});
}
Expand All @@ -646,6 +663,11 @@ impl LoadedPrograms {
entries.iter_mut().for_each(|entry| {
if entry.is_loaded() {
*entry = Arc::new(entry.to_unloaded());
self.stats
.evictions
.entry(*id)
.and_modify(|c| saturating_add_assign!(*c, 1))
.or_insert(1);
}
});
}
Expand Down Expand Up @@ -678,7 +700,14 @@ impl LoadedPrograms {
}

fn remove_programs_with_no_entries(&mut self) {
self.entries.retain(|_, programs| !programs.is_empty())
let num_programs_before_removal = self.entries.len();
self.entries.retain(|_, programs| !programs.is_empty());
if self.entries.len() < num_programs_before_removal {
self.stats.empty_entries.fetch_add(
num_programs_before_removal.saturating_sub(self.entries.len()) as u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just about the keys of the first index and has nothing to do with entries of the second index, like all other metrics do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is just counting how many programs were completely removed from the cache.

Ordering::Relaxed,
);
}
}
}

Expand Down