From 49da347d84a33c467d1309cbb912d418c4fada45 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Mon, 10 Jan 2022 21:23:41 +0000 Subject: [PATCH] limits gossip vote stats to the top most voted slots (#22416) --- gossip/src/cluster_info_metrics.rs | 38 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/gossip/src/cluster_info_metrics.rs b/gossip/src/cluster_info_metrics.rs index 1c97868f4..f136a05ae 100644 --- a/gossip/src/cluster_info_metrics.rs +++ b/gossip/src/cluster_info_metrics.rs @@ -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}, @@ -564,20 +565,8 @@ pub(crate) fn submit_gossip_stats( ("all-push", crds_stats.push.fails.iter().sum::(), i64), ("all-pull", crds_stats.pull.fails.iter().sum::(), 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 = crds_stats .pull .votes @@ -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, +{ + // 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),); } }