From ce7d2964c9bb7e730a3d32f84e947342e8ad371a Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Fri, 22 Apr 2022 15:01:51 -0500 Subject: [PATCH] metrics on ancient slots (#24596) --- runtime/src/accounts_db.rs | 42 ++++++++++++++++++++++++++++++++++++ runtime/src/accounts_hash.rs | 20 +++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 143eddb1bc..e946cf5d4d 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5403,6 +5403,27 @@ impl AccountsDb { } } + fn update_old_slot_stats( + &self, + stats: &HashStats, + sub_storages: Option<&Vec>>, + ) { + if let Some(sub_storages) = sub_storages { + stats.roots_older_than_epoch.fetch_add(1, Ordering::Relaxed); + let num_accounts = sub_storages.iter().map(|storage| storage.count()).sum(); + let sizes = sub_storages + .iter() + .map(|storage| storage.total_bytes()) + .sum::(); + stats + .append_vec_sizes_older_than_epoch + .fetch_add(sizes as usize, Ordering::Relaxed); + stats + .accounts_in_roots_older_than_epoch + .fetch_add(num_accounts, Ordering::Relaxed); + } + } + /// Scan through all the account storage in parallel fn scan_account_storage_no_bank( &self, @@ -5413,6 +5434,7 @@ impl AccountsDb { after_func: F2, bin_range: &Range, bin_calculator: &PubkeyBinCalculator24, + stats: &HashStats, ) -> Vec where F: Fn(LoadedAccount, &mut BinnedHashData, Slot) + Send + Sync, @@ -5459,6 +5481,15 @@ impl AccountsDb { retval.append(&mut vec![Vec::new(); range]); } + let slots_per_epoch = config + .rent_collector + .epoch_schedule + .get_slots_in_epoch(config.rent_collector.epoch); + let one_epoch_old = snapshot_storages + .range() + .end + .saturating_sub(slots_per_epoch); + let mut file_name = String::default(); // if we're using the write cache, we can't cache the hash calc results because not all accounts are in append vecs. if should_cache_hash_data && eligible_for_caching { @@ -5466,6 +5497,9 @@ impl AccountsDb { let mut hasher = std::collections::hash_map::DefaultHasher::new(); // wrong one? for (slot, sub_storages) in snapshot_storages.iter_range(start..end) { + if bin_range.start == 0 && slot < one_epoch_old { + self.update_old_slot_stats(stats, sub_storages); + } bin_range.start.hash(&mut hasher); bin_range.end.hash(&mut hasher); if let Some(sub_storages) = sub_storages { @@ -5517,6 +5551,12 @@ impl AccountsDb { // fall through and load normally - we failed to load } + } else { + for (slot, sub_storages) in snapshot_storages.iter_range(start..end) { + if bin_range.start == 0 && slot < one_epoch_old { + self.update_old_slot_stats(stats, sub_storages); + } + } } for (slot, sub_storages) in snapshot_storages.iter_range(start..end) { @@ -5778,6 +5818,7 @@ impl AccountsDb { }, bin_range, &bin_calculator, + stats, ); stats.sort_time_total_us += sort_time.load(Ordering::Relaxed); @@ -8246,6 +8287,7 @@ pub mod tests { |a| a, &Range { start: 0, end: 1 }, &PubkeyBinCalculator24::new(1), + &HashStats::default(), ); assert_eq!(calls.load(Ordering::Relaxed), 1); assert_eq!( diff --git a/runtime/src/accounts_hash.rs b/runtime/src/accounts_hash.rs index c247b6c4f0..d1c89df175 100644 --- a/runtime/src/accounts_hash.rs +++ b/runtime/src/accounts_hash.rs @@ -78,6 +78,9 @@ pub struct HashStats { pub rehash_required: AtomicUsize, /// # rehashes that took place and were UNnecessary pub rehash_unnecessary: AtomicUsize, + pub roots_older_than_epoch: AtomicUsize, + pub accounts_in_roots_older_than_epoch: AtomicUsize, + pub append_vec_sizes_older_than_epoch: AtomicUsize, } impl HashStats { pub fn calc_storage_size_quartiles(&mut self, storages: &SnapshotStorages) { @@ -192,6 +195,23 @@ impl HashStats { self.rehash_unnecessary.load(Ordering::Relaxed) as i64, i64 ), + ( + "roots_older_than_epoch", + self.roots_older_than_epoch.load(Ordering::Relaxed) as i64, + i64 + ), + ( + "append_vec_sizes_older_than_epoch", + self.append_vec_sizes_older_than_epoch + .load(Ordering::Relaxed) as i64, + i64 + ), + ( + "accounts_in_roots_older_than_epoch", + self.accounts_in_roots_older_than_epoch + .load(Ordering::Relaxed) as i64, + i64 + ), ); } }