Add set_root bank drop logging (#21144)

This commit is contained in:
carllin
2021-11-06 01:05:36 +00:00
committed by GitHub
parent 1b46d1d54d
commit 706b60b5c8

View File

@ -15,6 +15,16 @@ use std::{
time::Instant, time::Instant,
}; };
struct SetRootTimings {
total_banks: i64,
total_squash_cache_ms: i64,
total_squash_accounts_ms: i64,
total_snapshot_ms: i64,
tx_count: i64,
prune_non_rooted_ms: i64,
drop_parent_banks_ms: i64,
}
pub struct BankForks { pub struct BankForks {
banks: HashMap<Slot, Arc<Bank>>, banks: HashMap<Slot, Arc<Bank>>,
descendants: HashMap<Slot, HashSet<Slot>>, descendants: HashMap<Slot, HashSet<Slot>>,
@ -172,15 +182,14 @@ impl BankForks {
self[self.highest_slot()].clone() self[self.highest_slot()].clone()
} }
pub fn set_root( fn do_set_root_return_metrics(
&mut self, &mut self,
root: Slot, root: Slot,
accounts_background_request_sender: &AbsRequestSender, accounts_background_request_sender: &AbsRequestSender,
highest_confirmed_root: Option<Slot>, highest_confirmed_root: Option<Slot>,
) { ) -> SetRootTimings {
let old_epoch = self.root_bank().epoch(); let old_epoch = self.root_bank().epoch();
self.root = root; self.root = root;
let set_root_start = Instant::now();
let root_bank = self let root_bank = self
.banks .banks
.get(&root) .get(&root)
@ -189,9 +198,9 @@ impl BankForks {
if old_epoch != new_epoch { if old_epoch != new_epoch {
info!( info!(
"Root entering "Root entering
epoch: {}, epoch: {},
next_epoch_start_slot: {}, next_epoch_start_slot: {},
epoch_stakes: {:#?}", epoch_stakes: {:#?}",
new_epoch, new_epoch,
root_bank root_bank
.epoch_schedule() .epoch_schedule()
@ -223,8 +232,8 @@ impl BankForks {
{ {
self.last_accounts_hash_slot = bank_slot; self.last_accounts_hash_slot = bank_slot;
let squash_timing = bank.squash(); let squash_timing = bank.squash();
total_squash_accounts_ms += squash_timing.squash_accounts_ms; total_squash_accounts_ms += squash_timing.squash_accounts_ms as i64;
total_squash_cache_ms += squash_timing.squash_cache_ms; total_squash_cache_ms += squash_timing.squash_cache_ms as i64;
is_root_bank_squashed = bank_slot == root; is_root_bank_squashed = bank_slot == root;
let mut snapshot_time = Measure::start("squash::snapshot_time"); let mut snapshot_time = Measure::start("squash::snapshot_time");
@ -249,20 +258,47 @@ impl BankForks {
} }
} }
snapshot_time.stop(); snapshot_time.stop();
total_snapshot_ms += snapshot_time.as_ms(); total_snapshot_ms += snapshot_time.as_ms() as i64;
break; break;
} }
} }
if !is_root_bank_squashed { if !is_root_bank_squashed {
let squash_timing = root_bank.squash(); let squash_timing = root_bank.squash();
total_squash_accounts_ms += squash_timing.squash_accounts_ms; total_squash_accounts_ms += squash_timing.squash_accounts_ms as i64;
total_squash_cache_ms += squash_timing.squash_cache_ms; total_squash_cache_ms += squash_timing.squash_cache_ms as i64;
} }
let new_tx_count = root_bank.transaction_count(); let new_tx_count = root_bank.transaction_count();
let mut prune_time = Measure::start("set_root::prune"); let mut prune_time = Measure::start("set_root::prune");
self.prune_non_rooted(root, highest_confirmed_root); self.prune_non_rooted(root, highest_confirmed_root);
prune_time.stop(); prune_time.stop();
let mut drop_parent_banks_time = Measure::start("set_root::drop_banks");
drop(parents);
drop_parent_banks_time.stop();
SetRootTimings {
total_banks: total_banks as i64,
total_squash_cache_ms,
total_squash_accounts_ms,
total_snapshot_ms,
tx_count: (new_tx_count - root_tx_count) as i64,
prune_non_rooted_ms: prune_time.as_ms() as i64,
drop_parent_banks_ms: drop_parent_banks_time.as_ms() as i64,
}
}
pub fn set_root(
&mut self,
root: Slot,
accounts_background_request_sender: &AbsRequestSender,
highest_confirmed_root: Option<Slot>,
) {
let set_root_start = Instant::now();
let set_root_metrics = self.do_set_root_return_metrics(
root,
accounts_background_request_sender,
highest_confirmed_root,
);
datapoint_info!( datapoint_info!(
"bank-forks_set_root", "bank-forks_set_root",
( (
@ -271,12 +307,29 @@ impl BankForks {
i64 i64
), ),
("slot", root, i64), ("slot", root, i64),
("total_banks", total_banks, i64), ("total_banks", set_root_metrics.total_banks, i64),
("total_squash_cache_ms", total_squash_cache_ms, i64), (
("total_squash_accounts_ms", total_squash_accounts_ms, i64), "total_squash_cache_ms",
("total_snapshot_ms", total_snapshot_ms, i64), set_root_metrics.total_squash_cache_ms,
("tx_count", (new_tx_count - root_tx_count) as usize, i64), i64
("prune_non_rooted_ms", prune_time.as_ms(), i64), ),
(
"total_squash_accounts_ms",
set_root_metrics.total_squash_accounts_ms,
i64
),
("total_snapshot_ms", set_root_metrics.total_snapshot_ms, i64),
("tx_count", set_root_metrics.tx_count, i64),
(
"prune_non_rooted_ms",
set_root_metrics.prune_non_rooted_ms,
i64
),
(
"drop_parent_banks_ms",
set_root_metrics.drop_parent_banks_ms,
i64
),
); );
} }