From 1bfd6d0b256c47812b9a62f5e0c296b5a0be1f33 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 27 Sep 2024 14:09:52 -0400 Subject: [PATCH] Add ancient slots shrinking stats --- accounts-db/src/accounts_db.rs | 43 ++++++++++++++++++++++++++ accounts-db/src/ancient_append_vecs.rs | 3 ++ 2 files changed, 46 insertions(+) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index b162ee1abe9330..1e69623a546ac3 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1997,6 +1997,7 @@ pub(crate) struct ShrinkAncientStats { pub(crate) slots_eligible_to_shrink: AtomicU64, pub(crate) total_dead_bytes: AtomicU64, pub(crate) total_alive_bytes: AtomicU64, + pub(crate) ideal_storage_size: AtomicU64, } #[derive(Debug, Default)] @@ -2043,9 +2044,12 @@ pub struct ShrinkStats { index_scan_returned_none: AtomicU64, index_scan_returned_some: AtomicU64, accounts_loaded: AtomicU64, + initial_candidates_count: AtomicU64, purged_zero_lamports: AtomicU64, accounts_not_found_in_index: AtomicU64, num_ancient_slots_shrunk: AtomicU64, + ancient_slots_added_to_shrink: AtomicU64, + ancient_bytes_added_to_shrink: AtomicU64, } impl ShrinkStats { @@ -2053,6 +2057,18 @@ impl ShrinkStats { if self.last_report.should_update(1000) { datapoint_info!( "shrink_stats", + ( + "ancient_slots_added_to_shrink", + self.ancient_slots_added_to_shrink + .swap(0, Ordering::Relaxed) as i64, + i64 + ), + ( + "ancient_bytes_added_to_shrink", + self.ancient_bytes_added_to_shrink + .swap(0, Ordering::Relaxed) as i64, + i64 + ), ( "num_slots_shrunk", self.num_slots_shrunk.swap(0, Ordering::Relaxed) as i64, @@ -2169,6 +2185,11 @@ impl ShrinkStats { self.accounts_not_found_in_index.swap(0, Ordering::Relaxed), i64 ), + ( + "initial_candidates_count", + self.initial_candidates_count.swap(0, Ordering::Relaxed), + i64 + ), ); } } @@ -2328,6 +2349,11 @@ impl ShrinkAncientStats { self.slots_eligible_to_shrink.swap(0, Ordering::Relaxed), i64 ), + ( + "ideal_storage_size", + self.ideal_storage_size.swap(0, Ordering::Relaxed), + i64 + ), ( "total_dead_bytes", self.total_dead_bytes.swap(0, Ordering::Relaxed), @@ -5074,6 +5100,10 @@ impl AccountsDb { let shrink_candidates_slots = std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap()); + self.shrink_stats + .initial_candidates_count + .store(shrink_candidates_slots.len() as u64, Ordering::Relaxed); + let (mut shrink_slots, shrink_slots_next_batch) = { if let AccountShrinkThreshold::TotalSpace { shrink_ratio } = self.shrink_ratio { let (shrink_slots, shrink_slots_next_batch) = @@ -5096,6 +5126,7 @@ impl AccountsDb { }; let mut limit = 2; + let mut ancient_slots_added = 0; if shrink_slots.len() >= limit { limit = shrink_slots.len() + 1; } @@ -5113,6 +5144,10 @@ impl AccountsDb { continue; } *capacity = 0; + ancient_slots_added += 1; + self.shrink_stats + .ancient_bytes_added_to_shrink + .fetch_add(store.alive_bytes() as u64, Ordering::Relaxed); shrink_slots.insert(*slot, store); if shrink_slots.len() >= limit { @@ -5120,6 +5155,14 @@ impl AccountsDb { } } } + log::debug!( + "ancient_slots_added: {ancient_slots_added}, {}, avail: {}", + shrink_slots.len(), + ancients.len() + ); + self.shrink_stats + .ancient_slots_added_to_shrink + .fetch_add(ancient_slots_added, Ordering::Relaxed); if shrink_slots.is_empty() && shrink_slots_next_batch .as_ref() diff --git a/accounts-db/src/ancient_append_vecs.rs b/accounts-db/src/ancient_append_vecs.rs index 6c8d3396d57252..757777424407b8 100644 --- a/accounts-db/src/ancient_append_vecs.rs +++ b/accounts-db/src/ancient_append_vecs.rs @@ -609,6 +609,9 @@ impl AccountsDb { (infos.total_alive_bytes.0 / tuning.max_ancient_slots.max(1) as u64 * 2).max(5_000_000), ) .unwrap(); + self.shrink_ancient_stats + .ideal_storage_size + .store(tuning.ideal_storage_size.into(), Ordering::Relaxed); self.shrink_ancient_stats .slots_eligible_to_shrink .fetch_add(should_shrink_count as u64, Ordering::Relaxed);