Skip to content

Commit

Permalink
limits gossip vote stats to the top most voted slots (solana-labs#22416)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored Jan 10, 2022
1 parent 2cc6f86 commit 49da347
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions gossip/src/cluster_info_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
solana_measure::measure::Measure,
solana_sdk::{clock::Slot, pubkey::Pubkey},
std::{
cmp::Reverse,
collections::HashMap,
ops::{Deref, DerefMut},
sync::atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -564,20 +565,8 @@ pub(crate) fn submit_gossip_stats(
("all-push", crds_stats.push.fails.iter().sum::<usize>(), i64),
("all-pull", crds_stats.pull.fails.iter().sum::<usize>(), i64),
);
for (slot, num_votes) in &crds_stats.pull.votes {
datapoint_info!(
"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),
);
}
submit_vote_stats("cluster_info_crds_stats_votes_pull", &crds_stats.pull.votes);
submit_vote_stats("cluster_info_crds_stats_votes_push", &crds_stats.push.votes);
let votes: HashMap<Slot, usize> = crds_stats
.pull
.votes
Expand All @@ -592,11 +581,20 @@ pub(crate) fn submit_gossip_stats(
)
.into_grouping_map()
.aggregate(|acc, _slot, num_votes| Some(acc.unwrap_or_default() + num_votes));
for (slot, num_votes) in votes {
datapoint_info!(
"cluster_info_crds_stats_votes",
("slot", slot, i64),
("num_votes", num_votes, i64),
);
submit_vote_stats("cluster_info_crds_stats_votes", &votes);
}

fn submit_vote_stats<'a, I>(name: &'static str, votes: I)
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),);
}
}

0 comments on commit 49da347

Please sign in to comment.