Skip to content

Commit

Permalink
Add ancient slots shrinking stats
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Sep 27, 2024
1 parent 003ba1f commit 1bfd6d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -2043,16 +2044,31 @@ 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 {
fn report(&self) {
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,
Expand Down Expand Up @@ -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
),
);
}
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) =
Expand All @@ -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;
}
Expand All @@ -5113,13 +5144,25 @@ 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 {
break;
}
}
}
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()
Expand Down
3 changes: 3 additions & 0 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1bfd6d0

Please sign in to comment.