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

Commit 4e2b4b7

Browse files
counts gossip packets received before excess packets are dropped (backport #28086) (#28105)
counts gossip packets received before excess packets are dropped (#28086) Currently, gossip packets are counted after excess packets are dropped. This makes it difficult to debug gossip traffic spikes if the majority of the packets are dropped. This commit instead counts gossip packets received before excess packets are dropped (cherry picked from commit abfaf06) Co-authored-by: behzad nouri <behzadnouri@gmail.com>
1 parent 1bbace4 commit 4e2b4b7

2 files changed

Lines changed: 61 additions & 16 deletions

File tree

gossip/src/cluster_info.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ pub(crate) enum Protocol {
275275
PruneMessage(Pubkey, PruneData),
276276
PingMessage(Ping),
277277
PongMessage(Pong),
278+
// Update count_packets_received if new variants are added here.
278279
}
279280

280281
impl Protocol {
@@ -2399,18 +2400,6 @@ impl ClusterInfo {
23992400
Protocol::PongMessage(pong) => pong_messages.push((from_addr, pong)),
24002401
}
24012402
}
2402-
self.stats
2403-
.packets_received_pull_requests_count
2404-
.add_relaxed(pull_requests.len() as u64);
2405-
self.stats
2406-
.packets_received_pull_responses_count
2407-
.add_relaxed(pull_responses.len() as u64);
2408-
self.stats
2409-
.packets_received_push_messages_count
2410-
.add_relaxed(push_messages.len() as u64);
2411-
self.stats
2412-
.packets_received_prune_messages_count
2413-
.add_relaxed(prune_messages.len() as u64);
24142403
if self.require_stake_for_gossip(stakes) {
24152404
for (_, data) in &mut pull_responses {
24162405
retain_staked(data, stakes);
@@ -2453,9 +2442,26 @@ impl ClusterInfo {
24532442
thread_pool: &ThreadPool,
24542443
) -> Result<(), GossipError> {
24552444
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
2456-
let packets: Vec<_> = receiver.recv_timeout(RECV_TIMEOUT)?.into();
2445+
fn count_packets_received(packets: &PacketBatch, counts: &mut [u64; 7]) {
2446+
for packet in packets {
2447+
let k = match packet
2448+
.data(..4)
2449+
.and_then(|data| <[u8; 4]>::try_from(data).ok())
2450+
.map(u32::from_le_bytes)
2451+
{
2452+
Some(k @ 0..=6) => k as usize,
2453+
None | Some(_) => 6,
2454+
};
2455+
counts[k] += 1;
2456+
}
2457+
}
2458+
let packets = receiver.recv_timeout(RECV_TIMEOUT)?;
2459+
let mut counts = [0u64; 7];
2460+
count_packets_received(&packets, &mut counts);
2461+
let packets = Vec::from(packets);
24572462
let mut packets = VecDeque::from(packets);
24582463
for packet_batch in receiver.try_iter() {
2464+
count_packets_received(&packet_batch, &mut counts);
24592465
packets.extend(packet_batch.iter().cloned());
24602466
let excess_count = packets.len().saturating_sub(MAX_GOSSIP_TRAFFIC);
24612467
if excess_count > 0 {
@@ -2465,9 +2471,6 @@ impl ClusterInfo {
24652471
.add_relaxed(excess_count as u64);
24662472
}
24672473
}
2468-
self.stats
2469-
.packets_received_count
2470-
.add_relaxed(packets.len() as u64);
24712474
let verify_packet = |packet: Packet| {
24722475
let protocol: Protocol = packet.deserialize_slice(..).ok()?;
24732476
protocol.sanitize().ok()?;
@@ -2478,6 +2481,30 @@ impl ClusterInfo {
24782481
let _st = ScopedTimer::from(&self.stats.verify_gossip_packets_time);
24792482
thread_pool.install(|| packets.into_par_iter().filter_map(verify_packet).collect())
24802483
};
2484+
self.stats
2485+
.packets_received_count
2486+
.add_relaxed(counts.iter().sum::<u64>());
2487+
self.stats
2488+
.packets_received_pull_requests_count
2489+
.add_relaxed(counts[0]);
2490+
self.stats
2491+
.packets_received_pull_responses_count
2492+
.add_relaxed(counts[1]);
2493+
self.stats
2494+
.packets_received_push_messages_count
2495+
.add_relaxed(counts[2]);
2496+
self.stats
2497+
.packets_received_prune_messages_count
2498+
.add_relaxed(counts[3]);
2499+
self.stats
2500+
.packets_received_ping_messages_count
2501+
.add_relaxed(counts[4]);
2502+
self.stats
2503+
.packets_received_pong_messages_count
2504+
.add_relaxed(counts[5]);
2505+
self.stats
2506+
.packets_received_unknown_count
2507+
.add_relaxed(counts[6]);
24812508
self.stats
24822509
.packets_received_verified_count
24832510
.add_relaxed(packets.len() as u64);

gossip/src/cluster_info_metrics.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ pub struct GossipStats {
127127
pub(crate) new_push_requests: Counter,
128128
pub(crate) new_push_requests_num: Counter,
129129
pub(crate) packets_received_count: Counter,
130+
pub(crate) packets_received_ping_messages_count: Counter,
131+
pub(crate) packets_received_pong_messages_count: Counter,
130132
pub(crate) packets_received_prune_messages_count: Counter,
131133
pub(crate) packets_received_pull_requests_count: Counter,
132134
pub(crate) packets_received_pull_responses_count: Counter,
133135
pub(crate) packets_received_push_messages_count: Counter,
136+
pub(crate) packets_received_unknown_count: Counter,
134137
pub(crate) packets_received_verified_count: Counter,
135138
pub(crate) packets_sent_gossip_requests_count: Counter,
136139
pub(crate) packets_sent_prune_messages_count: Counter,
@@ -454,6 +457,16 @@ pub(crate) fn submit_gossip_stats(
454457
stats.packets_received_count.clear(),
455458
i64
456459
),
460+
(
461+
"packets_received_ping_messages_count",
462+
stats.packets_received_ping_messages_count.clear(),
463+
i64
464+
),
465+
(
466+
"packets_received_pong_messages_count",
467+
stats.packets_received_pong_messages_count.clear(),
468+
i64
469+
),
457470
(
458471
"packets_received_prune_messages_count",
459472
stats.packets_received_prune_messages_count.clear(),
@@ -474,6 +487,11 @@ pub(crate) fn submit_gossip_stats(
474487
stats.packets_received_push_messages_count.clear(),
475488
i64
476489
),
490+
(
491+
"packets_received_unknown_count",
492+
stats.packets_received_unknown_count.clear(),
493+
i64
494+
),
477495
(
478496
"packets_received_verified_count",
479497
stats.packets_received_verified_count.clear(),

0 commit comments

Comments
 (0)