limits gossip vote stats to the top most voted slots (#22416)

This commit is contained in:
behzad nouri 2022-01-10 21:23:41 +00:00 committed by GitHub
parent 2cc6f863bf
commit 49da347d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 20 deletions

View File

@ -4,6 +4,7 @@ use {
solana_measure::measure::Measure, solana_measure::measure::Measure,
solana_sdk::{clock::Slot, pubkey::Pubkey}, solana_sdk::{clock::Slot, pubkey::Pubkey},
std::{ std::{
cmp::Reverse,
collections::HashMap, collections::HashMap,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
sync::atomic::{AtomicU64, Ordering}, sync::atomic::{AtomicU64, Ordering},
@ -564,20 +565,8 @@ pub(crate) fn submit_gossip_stats(
("all-push", crds_stats.push.fails.iter().sum::<usize>(), i64), ("all-push", crds_stats.push.fails.iter().sum::<usize>(), i64),
("all-pull", crds_stats.pull.fails.iter().sum::<usize>(), i64), ("all-pull", crds_stats.pull.fails.iter().sum::<usize>(), i64),
); );
for (slot, num_votes) in &crds_stats.pull.votes { submit_vote_stats("cluster_info_crds_stats_votes_pull", &crds_stats.pull.votes);
datapoint_info!( submit_vote_stats("cluster_info_crds_stats_votes_push", &crds_stats.push.votes);
"cluster_info_crds_stats_votes_pull",
("slot", *slot, i64),
("num_votes", *num_votes, i64),
);
}
for (slot, num_votes) in &crds_stats.push.votes {
datapoint_info!(
"cluster_info_crds_stats_votes_push",
("slot", *slot, i64),
("num_votes", *num_votes, i64),
);
}
let votes: HashMap<Slot, usize> = crds_stats let votes: HashMap<Slot, usize> = crds_stats
.pull .pull
.votes .votes
@ -592,11 +581,20 @@ pub(crate) fn submit_gossip_stats(
) )
.into_grouping_map() .into_grouping_map()
.aggregate(|acc, _slot, num_votes| Some(acc.unwrap_or_default() + num_votes)); .aggregate(|acc, _slot, num_votes| Some(acc.unwrap_or_default() + num_votes));
for (slot, num_votes) in votes { submit_vote_stats("cluster_info_crds_stats_votes", &votes);
datapoint_info!( }
"cluster_info_crds_stats_votes",
("slot", slot, i64), fn submit_vote_stats<'a, I>(name: &'static str, votes: I)
("num_votes", num_votes, i64), where
); I: IntoIterator<Item = (&'a Slot, /*num-votes:*/ &'a usize)>,
{
// Submit vote stats only for the top most voted slots.
const NUM_SLOTS: usize = 20;
let mut votes: Vec<_> = votes.into_iter().map(|(k, v)| (*k, *v)).collect();
if votes.len() > NUM_SLOTS {
votes.select_nth_unstable_by_key(NUM_SLOTS, |(_, num)| Reverse(*num));
}
for (slot, num_votes) in votes.into_iter().take(NUM_SLOTS) {
datapoint_info!(name, ("slot", slot, i64), ("num_votes", num_votes, i64),);
} }
} }