Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
adds gossip metrics for number of staked nodes (#17330)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored May 19, 2021
1 parent b5302e7 commit e7073ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 12 additions & 11 deletions core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ impl ClusterInfo {
thread_pool: &ThreadPool,
recycler: &PacketsRecycler,
response_sender: &PacketSender,
stakes: HashMap<Pubkey, u64>,
stakes: &HashMap<Pubkey, u64>,
feature_set: Option<&FeatureSet>,
epoch_time_ms: u64,
should_check_duplicate_instance: bool,
Expand Down Expand Up @@ -2637,13 +2637,13 @@ impl ClusterInfo {
self.stats
.packets_received_prune_messages_count
.add_relaxed(prune_messages.len() as u64);
let require_stake_for_gossip = self.require_stake_for_gossip(feature_set, &stakes);
let require_stake_for_gossip = self.require_stake_for_gossip(feature_set, stakes);
if require_stake_for_gossip {
for (_, data) in &mut pull_responses {
retain_staked(data, &stakes);
retain_staked(data, stakes);
}
for (_, data) in &mut push_messages {
retain_staked(data, &stakes);
retain_staked(data, stakes);
}
pull_responses.retain(|(_, data)| !data.is_empty());
push_messages.retain(|(_, data)| !data.is_empty());
Expand All @@ -2654,18 +2654,18 @@ impl ClusterInfo {
push_messages,
thread_pool,
recycler,
&stakes,
stakes,
response_sender,
require_stake_for_gossip,
);
self.handle_batch_pull_responses(pull_responses, thread_pool, &stakes, epoch_time_ms);
self.trim_crds_table(CRDS_UNIQUE_PUBKEY_CAPACITY, &stakes);
self.handle_batch_pull_responses(pull_responses, thread_pool, stakes, epoch_time_ms);
self.trim_crds_table(CRDS_UNIQUE_PUBKEY_CAPACITY, stakes);
self.handle_batch_pong_messages(pong_messages, Instant::now());
self.handle_batch_pull_requests(
pull_requests,
thread_pool,
recycler,
&stakes,
stakes,
response_sender,
require_stake_for_gossip,
);
Expand All @@ -2684,6 +2684,7 @@ impl ClusterInfo {
should_check_duplicate_instance: bool,
) -> Result<()> {
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
const SUBMIT_GOSSIP_STATS_INTERVAL: Duration = Duration::from_secs(2);
let packets: Vec<_> = requests_receiver.recv_timeout(RECV_TIMEOUT)?.packets.into();
let mut packets = VecDeque::from(packets);
while let Ok(packet) = requests_receiver.try_recv() {
Expand Down Expand Up @@ -2714,13 +2715,13 @@ impl ClusterInfo {
thread_pool,
recycler,
response_sender,
stakes,
&stakes,
feature_set.as_deref(),
epoch_time_ms,
should_check_duplicate_instance,
)?;
if last_print.elapsed().as_millis() > 2000 {
submit_gossip_stats(&self.stats, &self.gossip);
if last_print.elapsed() > SUBMIT_GOSSIP_STATS_INTERVAL {
submit_gossip_stats(&self.stats, &self.gossip, &stakes);
*last_print = Instant::now();
}
Ok(())
Expand Down
14 changes: 12 additions & 2 deletions core/src/cluster_info_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::crds_gossip::CrdsGossip;
use solana_measure::measure::Measure;
use solana_sdk::pubkey::Pubkey;
use std::{
collections::HashMap,
sync::{
atomic::{AtomicU64, Ordering},
RwLock,
Expand Down Expand Up @@ -116,15 +118,21 @@ pub(crate) struct GossipStats {
pub(crate) tvu_peers: Counter,
}

pub(crate) fn submit_gossip_stats(stats: &GossipStats, gossip: &RwLock<CrdsGossip>) {
let (table_size, purged_values_size, failed_inserts_size) = {
pub(crate) fn submit_gossip_stats(
stats: &GossipStats,
gossip: &RwLock<CrdsGossip>,
stakes: &HashMap<Pubkey, u64>,
) {
let (table_size, num_nodes, purged_values_size, failed_inserts_size) = {
let gossip = gossip.read().unwrap();
(
gossip.crds.len(),
gossip.crds.num_nodes(),
gossip.pull.purged_values.len(),
gossip.pull.failed_inserts.len(),
)
};
let num_nodes_staked = stakes.values().filter(|stake| **stake > 0).count();
datapoint_info!(
"cluster_info_stats",
("entrypoint", stats.entrypoint.clear(), i64),
Expand All @@ -142,6 +150,8 @@ pub(crate) fn submit_gossip_stats(stats: &GossipStats, gossip: &RwLock<CrdsGossi
("table_size", table_size as i64, i64),
("purged_values_size", purged_values_size as i64, i64),
("failed_inserts_size", failed_inserts_size as i64, i64),
("num_nodes", num_nodes as i64, i64),
("num_nodes_staked", num_nodes_staked as i64, i64),
);
datapoint_info!(
"cluster_info_stats2",
Expand Down

0 comments on commit e7073ec

Please sign in to comment.