add metrics around rewards (#24160)

This commit is contained in:
Jeff Washington (jwash)
2022-04-07 11:44:26 -05:00
committed by GitHub
parent f7b2951c79
commit 48d1af01c8

View File

@ -161,6 +161,14 @@ use {
}, },
}; };
#[derive(Debug, Default)]
struct RewardsMetrics {
load_vote_and_stake_accounts_us: AtomicU64,
calculate_points_us: AtomicU64,
store_stake_accounts_us: AtomicU64,
store_vote_accounts_us: AtomicU64,
}
mod address_lookup_table; mod address_lookup_table;
mod builtin_programs; mod builtin_programs;
mod sysvar_cache; mod sysvar_cache;
@ -1769,6 +1777,7 @@ impl Bank {
"update_epoch_stakes", "update_epoch_stakes",
); );
let metrics = RewardsMetrics::default();
// After saving a snapshot of stakes, apply stake rewards and commission // After saving a snapshot of stakes, apply stake rewards and commission
let (_, update_rewards_with_thread_pool_time) = Measure::this( let (_, update_rewards_with_thread_pool_time) = Measure::this(
|_| { |_| {
@ -1776,6 +1785,7 @@ impl Bank {
parent_epoch, parent_epoch,
reward_calc_tracer, reward_calc_tracer,
&thread_pool, &thread_pool,
&metrics,
) )
}, },
(), (),
@ -1804,6 +1814,26 @@ impl Bank {
update_rewards_with_thread_pool_time.as_us(), update_rewards_with_thread_pool_time.as_us(),
i64 i64
), ),
(
"load_vote_and_stake_accounts_us",
metrics.load_vote_and_stake_accounts_us.load(Relaxed),
i64
),
(
"calculate_points_us",
metrics.calculate_points_us.load(Relaxed),
i64
),
(
"store_stake_accounts_us",
metrics.store_stake_accounts_us.load(Relaxed),
i64
),
(
"store_vote_accounts_us",
metrics.store_vote_accounts_us.load(Relaxed),
i64
),
); );
} else { } else {
// Save a snapshot of stakes for use in consensus and stake weighted networking // Save a snapshot of stakes for use in consensus and stake weighted networking
@ -2460,6 +2490,7 @@ impl Bank {
prev_epoch: Epoch, prev_epoch: Epoch,
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>, reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
thread_pool: &ThreadPool, thread_pool: &ThreadPool,
metrics: &RewardsMetrics,
) { ) {
let slot_in_year = self.slot_in_year_for_inflation(); let slot_in_year = self.slot_in_year_for_inflation();
let epoch_duration_in_years = self.epoch_duration_in_years(prev_epoch); let epoch_duration_in_years = self.epoch_duration_in_years(prev_epoch);
@ -2484,6 +2515,7 @@ impl Bank {
reward_calc_tracer, reward_calc_tracer,
self.stake_program_advance_activating_credits_observed(), self.stake_program_advance_activating_credits_observed(),
thread_pool, thread_pool,
metrics,
); );
if !self if !self
@ -2672,9 +2704,11 @@ impl Bank {
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>, reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
fix_activating_credits_observed: bool, fix_activating_credits_observed: bool,
thread_pool: &ThreadPool, thread_pool: &ThreadPool,
metrics: &RewardsMetrics,
) -> f64 { ) -> f64 {
let stake_history = self.stakes_cache.stakes().history().clone(); let stake_history = self.stakes_cache.stakes().history().clone();
let vote_with_stake_delegations_map = { let vote_with_stake_delegations_map = {
let mut m = Measure::start("load_vote_and_stake_accounts_us");
let LoadVoteAndStakeAccountsResult { let LoadVoteAndStakeAccountsResult {
vote_with_stake_delegations_map, vote_with_stake_delegations_map,
invalid_stake_keys, invalid_stake_keys,
@ -2683,6 +2717,10 @@ impl Bank {
thread_pool, thread_pool,
reward_calc_tracer.as_ref(), reward_calc_tracer.as_ref(),
); );
m.stop();
metrics
.load_vote_and_stake_accounts_us
.fetch_add(m.as_us(), Relaxed);
let evict_invalid_stakes_cache_entries = self let evict_invalid_stakes_cache_entries = self
.feature_set .feature_set
@ -2696,6 +2734,7 @@ impl Bank {
vote_with_stake_delegations_map vote_with_stake_delegations_map
}; };
let mut m = Measure::start("calculate_points");
let points: u128 = thread_pool.install(|| { let points: u128 = thread_pool.install(|| {
vote_with_stake_delegations_map vote_with_stake_delegations_map
.par_iter() .par_iter()
@ -2720,6 +2759,8 @@ impl Bank {
}) })
.sum() .sum()
}); });
m.stop();
metrics.calculate_points_us.fetch_add(m.as_us(), Relaxed);
if points == 0 { if points == 0 {
return 0.0; return 0.0;
@ -2746,6 +2787,7 @@ impl Bank {
}, },
); );
let mut m = Measure::start("redeem_rewards");
let mut stake_rewards = thread_pool.install(|| { let mut stake_rewards = thread_pool.install(|| {
stake_delegation_iterator stake_delegation_iterator
.filter_map( .filter_map(
@ -2810,7 +2852,12 @@ impl Bank {
) )
.collect() .collect()
}); });
m.stop();
metrics
.store_stake_accounts_us
.fetch_add(m.as_us(), Relaxed);
let mut m = Measure::start("store_vote_accounts");
let mut vote_rewards = vote_account_rewards let mut vote_rewards = vote_account_rewards
.into_iter() .into_iter()
.filter_map( .filter_map(
@ -2841,6 +2888,9 @@ impl Bank {
) )
.collect(); .collect();
m.stop();
metrics.store_vote_accounts_us.fetch_add(m.as_us(), Relaxed);
{ {
let mut rewards = self.rewards.write().unwrap(); let mut rewards = self.rewards.write().unwrap();
rewards.append(&mut vote_rewards); rewards.append(&mut vote_rewards);