hopr_transport_session/counters.rs
1//! Process-global packet-flow diagnostic counters for the throughput stress harness.
2//!
3//! These counters were originally defined in `hopr-utils::parallelize`, but they encode
4//! HOPR session/routing domain concepts (session inbox, routing resolution, SPHINX encode
5//! stage) rather than generic parallelisation primitives. They therefore live here in the
6//! transport-session crate instead of the generic `hopr-utilities` crate.
7//!
8//! Each counter is a plain process-global atomic, incremented on hot paths across the
9//! transport/session pipeline and read (as deltas) by the load generator. They are not
10//! gated on any feature so they are available in every build, including test builds.
11
12use std::sync::atomic::{AtomicUsize, Ordering};
13
14/// Cumulative count of application data packets dropped because the session inbox
15/// channel was full (`try_send` returned `TrySendError::Full`).
16pub static SESSION_INBOX_DROPS: AtomicUsize = AtomicUsize::new(0);
17
18/// Returns the cumulative session inbox drop count.
19#[inline]
20pub fn session_inbox_drop_count() -> usize {
21 SESSION_INBOX_DROPS.load(Ordering::Relaxed)
22}
23
24/// Cumulative count of data packets dropped because no matching session slot was
25/// found in the session manager (`UnknownData` / unestablished-session path).
26pub static SESSION_UNKNOWN_DATA_DROPS: AtomicUsize = AtomicUsize::new(0);
27
28/// Returns the cumulative UnknownData drop count.
29#[inline]
30pub fn session_unknown_data_drop_count() -> usize {
31 SESSION_UNKNOWN_DATA_DROPS.load(Ordering::Relaxed)
32}
33
34/// Cumulative count of data packets dispatched as "unrelated" — reached dispatch_message
35/// but matched neither the session protocol tag nor any session application tag.
36pub static SESSION_UNRELATED_DATA_DISPATCHES: AtomicUsize = AtomicUsize::new(0);
37
38/// Returns the cumulative unrelated dispatch count.
39#[inline]
40pub fn session_unrelated_dispatch_count() -> usize {
41 SESSION_UNRELATED_DATA_DISPATCHES.load(Ordering::Relaxed)
42}
43
44/// Cumulative count of outgoing packets dropped because their return route still had no SURB
45/// when the resolution wait ran out.
46///
47/// Separate from [`ROUTING_RESOLUTION_FAILURES`] because it means something different and
48/// actionable: a counterparty has stopped replenishing SURBs and is not coming back, rather than a
49/// route that could not be computed. A non-zero and growing value names the condition that used to
50/// stall a node's entire egress indefinitely.
51pub static ROUTING_RESOLUTION_SURB_TIMEOUTS: AtomicUsize = AtomicUsize::new(0);
52
53/// Returns the cumulative count of packets dropped after waiting in vain for a return SURB.
54#[inline]
55pub fn routing_resolution_surb_timeout_count() -> usize {
56 ROUTING_RESOLUTION_SURB_TIMEOUTS.load(Ordering::Relaxed)
57}
58
59/// Cumulative count of packets that failed path/routing resolution before encoding.
60pub static ROUTING_RESOLUTION_FAILURES: AtomicUsize = AtomicUsize::new(0);
61
62/// Returns the cumulative routing resolution failure count.
63#[inline]
64pub fn routing_resolution_failure_count() -> usize {
65 ROUTING_RESOLUTION_FAILURES.load(Ordering::Relaxed)
66}
67
68/// Cumulative count of packets that successfully entered the routing resolution stage.
69pub static ROUTING_RESOLUTION_ATTEMPTS: AtomicUsize = AtomicUsize::new(0);
70
71/// Returns the cumulative routing resolution attempt count.
72#[inline]
73pub fn routing_resolution_attempt_count() -> usize {
74 ROUTING_RESOLUTION_ATTEMPTS.load(Ordering::Relaxed)
75}
76
77/// Cumulative count of packets that entered the SPHINX encode stage (spawn_encode_blocking called).
78pub static ENCODE_STAGE_ENTRIES: AtomicUsize = AtomicUsize::new(0);
79
80/// Returns the cumulative encode stage entry count.
81#[inline]
82pub fn encode_stage_entry_count() -> usize {
83 ENCODE_STAGE_ENTRIES.load(Ordering::Relaxed)
84}
85
86/// Cumulative count of calls to `smgr.dispatch_message` in SessionsManagement(0).
87/// Non-zero means packets are reaching the session manager dispatcher.
88pub static DISPATCH_MESSAGE_CALLS: AtomicUsize = AtomicUsize::new(0);
89
90/// Returns the cumulative dispatch_message call count.
91#[inline]
92pub fn dispatch_message_call_count() -> usize {
93 DISPATCH_MESSAGE_CALLS.load(Ordering::Relaxed)
94}
95
96/// Cumulative count of packets dropped by `forward_to_timeout(app_incoming)` at the ingress
97/// pipeline because `tx_from_protocol` was full for longer than `QUEUE_SEND_TIMEOUT` (50 ms).
98pub static APP_INCOMING_TIMEOUT_DROPS: AtomicUsize = AtomicUsize::new(0);
99
100/// Returns the cumulative app-incoming timeout drop count.
101#[inline]
102pub fn app_incoming_timeout_drop_count() -> usize {
103 APP_INCOMING_TIMEOUT_DROPS.load(Ordering::Relaxed)
104}