Skip to content

Commit

Permalink
Adds active stat items for clean subtasks
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Dec 19, 2024
1 parent f06f5db commit 7da6044
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
33 changes: 29 additions & 4 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,9 @@ impl AccountsDb {

self.report_store_stats();

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanConstructCandidates);
let mut key_timings = CleanKeyTimings::default();
let (candidates, min_dirty_slot) = self.construct_candidate_clean_keys(
max_clean_root_inclusive,
Expand All @@ -2805,9 +2808,9 @@ impl AccountsDb {
epoch_schedule,
old_storages_policy,
);
drop(active_guard);

let num_candidates = Self::count_pubkeys(&candidates);
let mut accounts_scan = Measure::start("accounts_scan");
let uncleaned_roots = self.accounts_index.clone_uncleaned_roots();
let found_not_zero_accum = AtomicU64::new(0);
let not_found_on_fork_accum = AtomicU64::new(0);
Expand Down Expand Up @@ -2940,27 +2943,37 @@ impl AccountsDb {
purges_old_accounts_count.fetch_add(purges_old_accounts_local, Ordering::Relaxed);
});
};
let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanScanCandidates);
let mut accounts_scan = Measure::start("accounts_scan");
if is_startup {
do_clean_scan();
} else {
self.thread_pool_clean.install(do_clean_scan);
}

accounts_scan.stop();
drop(active_guard);

let retained_keys_count = Self::count_pubkeys(&candidates);
let reclaims = reclaims.into_inner().unwrap();
let mut pubkeys_removed_from_accounts_index =
pubkeys_removed_from_accounts_index.into_inner().unwrap();

let active_guard = self.active_stats.activate(ActiveStatItem::CleanOldAccounts);
let mut clean_old_rooted = Measure::start("clean_old_roots");
let (purged_account_slots, removed_accounts) =
self.clean_accounts_older_than_root(&reclaims, &pubkeys_removed_from_accounts_index);
self.do_reset_uncleaned_roots(max_clean_root_inclusive);
clean_old_rooted.stop();

let mut store_counts_time = Measure::start("store_counts");
drop(active_guard);

// Calculate store counts as if everything was purged
// Then purge if we can
let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanCollectStoreCounts);
let mut store_counts_time = Measure::start("store_counts");
let mut store_counts: HashMap<Slot, (usize, HashSet<Pubkey>)> = HashMap::new();
for candidates_bin in candidates.iter() {
for (
Expand Down Expand Up @@ -3027,19 +3040,29 @@ impl AccountsDb {
}
}
store_counts_time.stop();
drop(active_guard);

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanCalcDeleteDeps);
let mut calc_deps_time = Measure::start("calc_deps");
self.calc_delete_dependencies(&candidates, &mut store_counts, min_dirty_slot);
calc_deps_time.stop();
drop(active_guard);

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanFilterZeroLamport);
let mut purge_filter = Measure::start("purge_filter");
self.filter_zero_lamport_clean_for_incremental_snapshots(
max_clean_root_inclusive,
&store_counts,
&candidates,
);
purge_filter.stop();
drop(active_guard);

let active_guard = self.active_stats.activate(ActiveStatItem::CleanReclaims);
let mut reclaims_time = Measure::start("reclaims");
// Recalculate reclaims with new purge set
let mut pubkey_to_slot_set = Vec::new();
Expand Down Expand Up @@ -3081,6 +3104,8 @@ impl AccountsDb {
);

reclaims_time.stop();
drop(active_guard);

measure_all.stop();

self.clean_accounts_stats.report();
Expand Down
47 changes: 47 additions & 0 deletions accounts-db/src/active_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Debug, Default)]
pub struct ActiveStats {
clean: AtomicUsize,
clean_construct_candidates: AtomicUsize,
clean_scan_candidates: AtomicUsize,
clean_old_accounts: AtomicUsize,
clean_collect_store_counts: AtomicUsize,
clean_calc_delete_deps: AtomicUsize,
clean_filter_zero_lamport: AtomicUsize,
clean_reclaims: AtomicUsize,
squash_ancient: AtomicUsize,
shrink: AtomicUsize,
hash: AtomicUsize,
Expand All @@ -17,6 +24,13 @@ pub struct ActiveStats {
#[derive(Debug, Copy, Clone)]
pub enum ActiveStatItem {
Clean,
CleanConstructCandidates,
CleanScanCandidates,
CleanOldAccounts,
CleanCollectStoreCounts,
CleanCalcDeleteDeps,
CleanFilterZeroLamport,
CleanReclaims,
Shrink,
SquashAncient,
Hash,
Expand Down Expand Up @@ -56,6 +70,13 @@ impl ActiveStats {
fn update_and_log(&self, item: ActiveStatItem, modify_stat: impl Fn(&AtomicUsize) -> usize) {
let stat = match item {
ActiveStatItem::Clean => &self.clean,
ActiveStatItem::CleanConstructCandidates => &self.clean_construct_candidates,
ActiveStatItem::CleanScanCandidates => &self.clean_scan_candidates,
ActiveStatItem::CleanOldAccounts => &self.clean_old_accounts,
ActiveStatItem::CleanCollectStoreCounts => &self.clean_collect_store_counts,
ActiveStatItem::CleanCalcDeleteDeps => &self.clean_calc_delete_deps,
ActiveStatItem::CleanFilterZeroLamport => &self.clean_filter_zero_lamport,
ActiveStatItem::CleanReclaims => &self.clean_reclaims,
ActiveStatItem::Shrink => &self.shrink,
ActiveStatItem::SquashAncient => &self.squash_ancient,
ActiveStatItem::Hash => &self.hash,
Expand All @@ -67,6 +88,32 @@ impl ActiveStats {
let value = modify_stat(stat);
match item {
ActiveStatItem::Clean => datapoint_info!("accounts_db_active", ("clean", value, i64)),
ActiveStatItem::CleanConstructCandidates => datapoint_info!(
"accounts_db_active",
("clean_construct_candidates", value, i64),
),
ActiveStatItem::CleanScanCandidates => {
datapoint_info!("accounts_db_active", ("clean_scan_candidates", value, i64))
}
ActiveStatItem::CleanOldAccounts => {
datapoint_info!("accounts_db_active", ("clean_old_accounts", value, i64))
}
ActiveStatItem::CleanCollectStoreCounts => {
datapoint_info!(
"accounts_db_active",
("clean_collect_store_counts", value, i64),
)
}
ActiveStatItem::CleanCalcDeleteDeps => {
datapoint_info!("accounts_db_active", ("clean_calc_delete_deps", value, i64))
}
ActiveStatItem::CleanFilterZeroLamport => datapoint_info!(
"accounts_db_active",
("clean_filter_zero_lamport", value, i64),
),
ActiveStatItem::CleanReclaims => {
datapoint_info!("accounts_db_active", ("clean_reclaims", value, i64))
}
ActiveStatItem::SquashAncient => {
datapoint_info!("accounts_db_active", ("squash_ancient", value, i64))
}
Expand Down

0 comments on commit 7da6044

Please sign in to comment.