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 Jul 22, 2024
1 parent 858d564 commit 265363a
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
40 changes: 40 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3198,6 +3198,9 @@ impl AccountsDb {

self.report_store_stats();

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanCollectCandidates);
let mut key_timings = CleanKeyTimings::default();
let (mut pubkeys, min_dirty_slot) = self.construct_candidate_clean_keys(
max_clean_root_inclusive,
Expand All @@ -3206,7 +3209,11 @@ impl AccountsDb {
&mut key_timings,
epoch_schedule,
);
drop(active_guard);

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanSortCandidates);
let mut sort = Measure::start("sort");
if is_startup {
pubkeys.par_sort_unstable();
Expand All @@ -3215,8 +3222,12 @@ impl AccountsDb {
.install(|| pubkeys.par_sort_unstable());
}
sort.stop();
drop(active_guard);

let total_keys_count = pubkeys.len();
let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanScanCandidates);
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);
Expand Down Expand Up @@ -3322,14 +3333,17 @@ impl AccountsDb {
},
)
};

if is_startup {
do_clean_scan()
} else {
self.thread_pool_clean.install(do_clean_scan)
}
};
accounts_scan.stop();
drop(active_guard);

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), mut pubkeys_removed_from_accounts_index) =
self.clean_accounts_older_than_root(
Expand All @@ -3341,7 +3355,11 @@ impl AccountsDb {

self.do_reset_uncleaned_roots(max_clean_root_inclusive);
clean_old_rooted.stop();
drop(active_guard);

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanCollectStoreCounts);
let mut store_counts_time = Measure::start("store_counts");

// Calculate store counts as if everything was purged
Expand Down Expand Up @@ -3398,11 +3416,19 @@ 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(&purges_zero_lamports, &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,
Expand All @@ -3411,9 +3437,14 @@ impl AccountsDb {
&mut purges_zero_lamports,
);
purge_filter.stop();
drop(active_guard);

let mut reclaims_time = Measure::start("reclaims");

// Recalculate reclaims with new purge set
let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanCollectReclaims);
let pubkey_to_slot_set: Vec<_> = purges_zero_lamports
.into_iter()
.map(|(key, (slots_list, _ref_count))| {
Expand All @@ -3426,13 +3457,21 @@ impl AccountsDb {
)
})
.collect();
drop(active_guard);

let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanPurgeReclaims);
let (reclaims, pubkeys_removed_from_accounts_index2) =
self.purge_keys_exact(pubkey_to_slot_set.iter());
pubkeys_removed_from_accounts_index.extend(pubkeys_removed_from_accounts_index2);
drop(active_guard);

// Don't reset from clean, since the pubkeys in those stores may need to be unref'ed
// and those stores may be used for background hashing.
let active_guard = self
.active_stats
.activate(ActiveStatItem::CleanHandleReclaims);
let reset_accounts = false;
self.handle_reclaims(
(!reclaims.is_empty()).then(|| reclaims.iter()),
Expand All @@ -3441,6 +3480,7 @@ impl AccountsDb {
&pubkeys_removed_from_accounts_index,
HandleReclaims::ProcessDeadSlots(&self.clean_accounts_stats.purge_stats),
);
drop(active_guard);

reclaims_time.stop();
measure_all.stop();
Expand Down
65 changes: 65 additions & 0 deletions accounts-db/src/active_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Debug, Default)]
pub struct ActiveStats {
clean: AtomicUsize,
clean_collect_candidates: AtomicUsize,
clean_sort_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_collect_reclaims: AtomicUsize,
clean_purge_reclaims: AtomicUsize,
clean_handle_reclaims: AtomicUsize,
squash_ancient: AtomicUsize,
shrink: AtomicUsize,
hash: AtomicUsize,
Expand All @@ -17,6 +27,16 @@ pub struct ActiveStats {
#[derive(Debug, Copy, Clone)]
pub enum ActiveStatItem {
Clean,
CleanCollectCandidates,
CleanSortCandidates,
CleanScanCandidates,
CleanOldAccounts,
CleanCollectStoreCounts,
CleanCalcDeleteDeps,
CleanFilterZeroLamport,
CleanCollectReclaims,
CleanPurgeReclaims,
CleanHandleReclaims,
Shrink,
SquashAncient,
Hash,
Expand Down Expand Up @@ -56,6 +76,16 @@ impl ActiveStats {
fn update_and_log(&self, item: ActiveStatItem, modify_stat: impl Fn(&AtomicUsize) -> usize) {
let stat = match item {
ActiveStatItem::Clean => &self.clean,
ActiveStatItem::CleanCollectCandidates => &self.clean_collect_candidates,
ActiveStatItem::CleanSortCandidates => &self.clean_sort_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::CleanCollectReclaims => &self.clean_collect_reclaims,
ActiveStatItem::CleanPurgeReclaims => &self.clean_purge_reclaims,
ActiveStatItem::CleanHandleReclaims => &self.clean_handle_reclaims,
ActiveStatItem::Shrink => &self.shrink,
ActiveStatItem::SquashAncient => &self.squash_ancient,
ActiveStatItem::Hash => &self.hash,
Expand All @@ -67,6 +97,41 @@ impl ActiveStats {
let value = modify_stat(stat);
match item {
ActiveStatItem::Clean => datapoint_info!("accounts_db_active", ("clean", value, i64)),
ActiveStatItem::CleanCollectCandidates => datapoint_info!(
"accounts_db_active",
("clean_collect_candidates", value, i64),
),
ActiveStatItem::CleanSortCandidates => {
datapoint_info!("accounts_db_active", ("clean_sort_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::CleanCollectReclaims => {
datapoint_info!("accounts_db_active", ("clean_collect_reclaims", value, i64))
}
ActiveStatItem::CleanPurgeReclaims => {
datapoint_info!("accounts_db_active", ("clean_purge_reclaims", value, i64))
}
ActiveStatItem::CleanHandleReclaims => {
datapoint_info!("accounts_db_active", ("clean_handle_reclaims", value, i64))
}
ActiveStatItem::SquashAncient => {
datapoint_info!("accounts_db_active", ("squash_ancient", value, i64))
}
Expand Down

0 comments on commit 265363a

Please sign in to comment.