From f31ca8ba8cf4da1441eca58135c83fcbb222a71f Mon Sep 17 00:00:00 2001 From: sakridge Date: Mon, 22 Nov 2021 16:47:58 +0000 Subject: [PATCH] Report cluster slots size (#21380) --- core/src/cluster_slots.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/src/cluster_slots.rs b/core/src/cluster_slots.rs index 5bdafde0cc..92b4cc2527 100644 --- a/core/src/cluster_slots.rs +++ b/core/src/cluster_slots.rs @@ -7,6 +7,7 @@ use { solana_sdk::{ clock::{Slot, DEFAULT_SLOTS_PER_EPOCH}, pubkey::Pubkey, + timing::AtomicInterval, }, std::{ collections::{BTreeMap, HashMap}, @@ -26,6 +27,7 @@ pub struct ClusterSlots { validator_stakes: RwLock>, epoch: RwLock>, cursor: Mutex, + last_report: AtomicInterval, } impl ClusterSlots { @@ -99,6 +101,36 @@ impl ClusterSlots { cluster_slots.split_off(&key); } } + self.report_cluster_slots_size(); + } + + fn report_cluster_slots_size(&self) { + if self.last_report.should_update(10_000) { + let (cluster_slots_cap, pubkeys_capacity) = { + let cluster_slots = self.cluster_slots.read().unwrap(); + let cluster_slots_cap = cluster_slots.len(); + let pubkeys_capacity = cluster_slots + .iter() + .map(|(_slot, slot_pubkeys)| slot_pubkeys.read().unwrap().capacity()) + .sum::(); + (cluster_slots_cap, pubkeys_capacity) + }; + let (validator_stakes_cap, validator_pubkeys_len) = { + let validator_stakes = self.validator_stakes.read().unwrap(); + let validator_len = validator_stakes + .iter() + .map(|(_pubkey, vote_accounts)| vote_accounts.vote_accounts.capacity()) + .sum::(); + (validator_stakes.capacity(), validator_len) + }; + datapoint_info!( + "cluster-slots-size", + ("cluster_slots_capacity", cluster_slots_cap, i64), + ("pubkeys_capacity", pubkeys_capacity, i64), + ("validator_stakes_capacity", validator_stakes_cap, i64), + ("validator_pubkeys_len", validator_pubkeys_len, i64), + ); + } } #[cfg(test)]