Skip to content

Commit

Permalink
report pubsub stats every 2s (solana-labs#21192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbiseda authored Nov 6, 2021
1 parent 706b60b commit 7659a2e
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions rpc/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,40 @@ fn initial_last_notified_slot(
}
}

#[derive(Default)]
struct PubsubNotificationStats {
since: Option<Instant>,
notification_entry_processing_count: u64,
notification_entry_processing_time_us: u64,
}

impl PubsubNotificationStats {
fn maybe_submit(&mut self) {
const SUBMIT_CADENCE: Duration = Duration::from_secs(2);
let elapsed = self.since.as_ref().map(Instant::elapsed);
if elapsed.unwrap_or(Duration::MAX) < SUBMIT_CADENCE {
return;
}
datapoint_info!(
"pubsub_notification_entries",
(
"notification_entry_processing_count",
self.notification_entry_processing_count,
i64
),
(
"notification_entry_processing_time_us",
self.notification_entry_processing_time_us,
i64
),
);
*self = Self {
since: Some(Instant::now()),
..Self::default()
};
}
}

pub struct RpcSubscriptions {
notification_sender: Sender<TimestampedNotificationEntry>,
t_cleanup: Option<JoinHandle<()>>,
Expand Down Expand Up @@ -618,6 +652,8 @@ impl RpcSubscriptions {
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
) {
let mut stats = PubsubNotificationStats::default();

loop {
if exit.load(Ordering::Relaxed) {
break;
Expand Down Expand Up @@ -738,14 +774,9 @@ impl RpcSubscriptions {
}
}
}
datapoint_info!(
"pubsub_notification_entries",
(
"notification_entry_processing_time_us",
queued_at.elapsed().as_micros() as i64,
i64
)
);
stats.notification_entry_processing_time_us +=
queued_at.elapsed().as_micros() as u64;
stats.notification_entry_processing_count += 1;
}
Err(RecvTimeoutError::Timeout) => {
// not a problem - try reading again
Expand All @@ -755,6 +786,7 @@ impl RpcSubscriptions {
break;
}
}
stats.maybe_submit();
}
}

Expand Down

0 comments on commit 7659a2e

Please sign in to comment.