add metric for collecting storages (#17527) (#17675)

(cherry picked from commit 72bb271a94)

# Conflicts:
#	runtime/src/accounts_db.rs
#	runtime/src/snapshot_utils.rs

Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-06-03 05:34:32 +00:00
committed by GitHub
parent eb1a04af65
commit a00fbbf5ca
3 changed files with 32 additions and 6 deletions

View File

@ -4244,11 +4244,19 @@ impl AccountsDb {
check_hash: bool, check_hash: bool,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
if !use_index { if !use_index {
let mut time = Measure::start("collect");
let combined_maps = self.get_snapshot_storages(slot); let combined_maps = self.get_snapshot_storages(slot);
time.stop();
let timings = HashStats {
collect_snapshots_us: time.as_us(),
..HashStats::default()
};
Self::calculate_accounts_hash_without_index( Self::calculate_accounts_hash_without_index(
&combined_maps, &combined_maps,
Some(&self.thread_pool_clean), Some(&self.thread_pool_clean),
timings,
check_hash, check_hash,
) )
} else { } else {
@ -4365,10 +4373,10 @@ impl AccountsDb {
pub fn calculate_accounts_hash_without_index( pub fn calculate_accounts_hash_without_index(
storages: &[SnapshotStorage], storages: &[SnapshotStorage],
thread_pool: Option<&ThreadPool>, thread_pool: Option<&ThreadPool>,
mut stats: HashStats,
check_hash: bool, check_hash: bool,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
let scan_and_hash = || { let mut scan_and_hash = move || {
let mut stats = HashStats::default();
// When calculating hashes, it is helpful to break the pubkeys found into bins based on the pubkey value. // When calculating hashes, it is helpful to break the pubkeys found into bins based on the pubkey value.
// More bins means smaller vectors to sort, copy, etc. // More bins means smaller vectors to sort, copy, etc.
const PUBKEY_BINS_FOR_CALCULATING_HASHES: usize = 64; const PUBKEY_BINS_FOR_CALCULATING_HASHES: usize = 64;
@ -5950,8 +5958,13 @@ pub mod tests {
solana_logger::setup(); solana_logger::setup();
let (storages, _size, _slot_expected) = sample_storage(); let (storages, _size, _slot_expected) = sample_storage();
let result = let result = AccountsDb::calculate_accounts_hash_without_index(
AccountsDb::calculate_accounts_hash_without_index(&storages, None, false).unwrap(); &storages,
None,
HashStats::default(),
false,
)
.unwrap();
let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap(); let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap();
assert_eq!(result, (expected_hash, 0)); assert_eq!(result, (expected_hash, 0));
} }
@ -5966,8 +5979,13 @@ pub mod tests {
item.hash item.hash
}); });
let sum = raw_expected.iter().map(|item| item.lamports).sum(); let sum = raw_expected.iter().map(|item| item.lamports).sum();
let result = let result = AccountsDb::calculate_accounts_hash_without_index(
AccountsDb::calculate_accounts_hash_without_index(&storages, None, false).unwrap(); &storages,
None,
HashStats::default(),
false,
)
.unwrap();
assert_eq!(result, (expected_hash, sum)); assert_eq!(result, (expected_hash, sum));
} }

View File

@ -28,6 +28,7 @@ pub struct HashStats {
pub hash_total: usize, pub hash_total: usize,
pub unreduced_entries: usize, pub unreduced_entries: usize,
pub num_snapshot_storage: usize, pub num_snapshot_storage: usize,
pub collect_snapshots_us: u64,
} }
impl HashStats { impl HashStats {
fn log(&mut self) { fn log(&mut self) {
@ -35,6 +36,7 @@ impl HashStats {
+ self.zeros_time_total_us + self.zeros_time_total_us
+ self.hash_time_total_us + self.hash_time_total_us
+ self.sort_time_total_us + self.sort_time_total_us
+ self.collect_snapshots_us
+ self.flatten_time_total_us; + self.flatten_time_total_us;
datapoint_info!( datapoint_info!(
"calculate_accounts_hash_without_index", "calculate_accounts_hash_without_index",
@ -45,6 +47,11 @@ impl HashStats {
("hash_total", self.hash_total, i64), ("hash_total", self.hash_total, i64),
("flatten", self.flatten_time_total_us, i64), ("flatten", self.flatten_time_total_us, i64),
("unreduced_entries", self.unreduced_entries as i64, i64), ("unreduced_entries", self.unreduced_entries as i64, i64),
(
"collect_snapshots_us",
self.collect_snapshots_us as i64,
i64
),
( (
"num_snapshot_storage", "num_snapshot_storage",
self.num_snapshot_storage as i64, self.num_snapshot_storage as i64,

View File

@ -1001,6 +1001,7 @@ pub fn process_accounts_package_pre(
let (hash, lamports) = AccountsDb::calculate_accounts_hash_without_index( let (hash, lamports) = AccountsDb::calculate_accounts_hash_without_index(
&accounts_package.storages, &accounts_package.storages,
thread_pool, thread_pool,
crate::accounts_hash::HashStats::default(),
false, false,
) )
.unwrap(); .unwrap();