Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ancient.total_alive_bytes metric #2828

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ pub(crate) struct ShrinkAncientStats {
pub(crate) many_refs_old_alive: AtomicU64,
pub(crate) slots_eligible_to_shrink: AtomicU64,
pub(crate) total_dead_bytes: AtomicU64,
pub(crate) total_alive_bytes: AtomicU64,
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -2320,6 +2321,11 @@ impl ShrinkAncientStats {
self.total_dead_bytes.swap(0, Ordering::Relaxed),
i64
),
(
"total_alive_bytes",
self.total_alive_bytes.swap(0, Ordering::Relaxed),
i64
),
(
"slots_considered",
self.slots_considered.swap(0, Ordering::Relaxed) as i64,
Expand Down
9 changes: 8 additions & 1 deletion accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,15 @@ impl AccountsDb {
}
}
let mut total_dead_bytes = 0;
let mut total_alive_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))
.map(|info| {
total_dead_bytes += info.capacity.saturating_sub(info.alive_bytes);
total_alive_bytes += info.alive_bytes;

Choose a reason for hiding this comment

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

I was initially curious how we guaranteed slots was all the ancient storages, otherwise this wouldn't be a 'total', per se.

I see we get slots by calling AccountsDb::get_sorted_potential_ancient_slots(). I believe it is safe for this function to assume/require that slots is correct.

And assuming we use 'pack', then the stats are reported after each invocation of combine_ancient_slots_packed(), so I think that also ensures we don't sum up multiple 'totals' too.

})
.count()
.saturating_sub(randoms as usize);
self.shrink_ancient_stats
Expand All @@ -597,6 +601,9 @@ impl AccountsDb {
self.shrink_ancient_stats
.total_dead_bytes
.fetch_add(total_dead_bytes, Ordering::Relaxed);
self.shrink_ancient_stats
.total_alive_bytes
.fetch_add(total_alive_bytes, Ordering::Relaxed);
if randoms > 0 {
self.shrink_ancient_stats
.random_shrink
Expand Down