From 54935e703ef5df07445b898bff75c8033efb9e95 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Fri, 19 Jul 2024 14:39:44 -0500 Subject: [PATCH] add ancient pack metrics (#2206) --- accounts-db/src/accounts_db.rs | 12 ++++++++++++ accounts-db/src/ancient_append_vecs.rs | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 159cc4c5f99c83..84356b91783f19 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1957,6 +1957,8 @@ pub(crate) struct ShrinkAncientStats { pub(crate) many_ref_slots_skipped: AtomicU64, pub(crate) slots_cannot_move_count: AtomicU64, pub(crate) many_refs_old_alive: AtomicU64, + pub(crate) slots_eligible_to_shrink: AtomicU64, + pub(crate) total_dead_bytes: AtomicU64, } #[derive(Debug, Default)] @@ -2239,6 +2241,16 @@ impl ShrinkAncientStats { self.random_shrink.swap(0, Ordering::Relaxed) as i64, i64 ), + ( + "slots_eligible_to_shrink", + self.slots_eligible_to_shrink.swap(0, Ordering::Relaxed), + i64 + ), + ( + "total_dead_bytes", + self.total_dead_bytes.swap(0, Ordering::Relaxed), + i64 + ), ( "slots_considered", self.slots_considered.swap(0, Ordering::Relaxed) as i64, diff --git a/accounts-db/src/ancient_append_vecs.rs b/accounts-db/src/ancient_append_vecs.rs index c32319fde67e25..427478e857ed4a 100644 --- a/accounts-db/src/ancient_append_vecs.rs +++ b/accounts-db/src/ancient_append_vecs.rs @@ -572,6 +572,20 @@ impl AccountsDb { } } } + let mut total_dead_bytes = 0; + let should_shrink_count = infos + .all_infos + .iter() + .filter(|info| info.should_shrink) + .map(|info| total_dead_bytes += info.capacity.saturating_sub(info.alive_bytes)) + .count() + .saturating_sub(randoms as usize); + self.shrink_ancient_stats + .slots_eligible_to_shrink + .fetch_add(should_shrink_count as u64, Ordering::Relaxed); + self.shrink_ancient_stats + .total_dead_bytes + .fetch_add(total_dead_bytes, Ordering::Relaxed); if randoms > 0 { self.shrink_ancient_stats .random_shrink