Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report ConsumeWorkerMetrics at slot transitions #3212

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
solana_measure::measure_us,
solana_poh::leader_bank_notifier::LeaderBankNotifier,
solana_runtime::bank::Bank,
solana_sdk::timing::AtomicInterval,
solana_sdk::clock::Slot,
solana_svm::transaction_error_metrics::TransactionErrorMetrics,
std::{
sync::{
Expand Down Expand Up @@ -170,32 +170,43 @@ fn try_drain_iter<T>(work: T, receiver: &Receiver<T>) -> impl Iterator<Item = T>
/// done.
pub(crate) struct ConsumeWorkerMetrics {
id: String,
interval: AtomicInterval,
has_data: AtomicBool,
slot: AtomicU64,

count_metrics: ConsumeWorkerCountMetrics,
error_metrics: ConsumeWorkerTransactionErrorMetrics,
timing_metrics: ConsumeWorkerTimingMetrics,
}

impl ConsumeWorkerMetrics {
/// Report and reset metrics iff the interval has elapsed and the worker did some work.
pub fn maybe_report_and_reset(&self) {
const REPORT_INTERVAL_MS: u64 = 1000;
if self.interval.should_update(REPORT_INTERVAL_MS)
&& self.has_data.swap(false, Ordering::Relaxed)
{
/// Report and reset metrics when the worker did some work and:
/// a) (when a leader) Previous slot is not the same as current.
/// b) (when not a leader) report the metrics accumulated so far.
pub fn maybe_report_and_reset(&self, slot: Option<Slot>) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function may be called more than once per leader slot.
we need to check that the slot is different than the cached slot before resetting has_data

let prev_slot_id: u64 = self.slot.load(Ordering::Relaxed);
if let Some(slot) = slot {
if slot != prev_slot_id {
if !self.has_data.swap(false, Ordering::Relaxed) {
return;
}
self.count_metrics.report_and_reset(&self.id);
self.timing_metrics.report_and_reset(&self.id);
self.error_metrics.report_and_reset(&self.id);
Copy link

@apfitzge apfitzge Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to report the slot on these metrics too. otherwise we can't directly associate them

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably best to add slot in the name of the metrics as well so that they don't get mixed during transition period

self.slot.swap(slot, Ordering::Relaxed);
}
} else if prev_slot_id != 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to reset self.slot in here. otherwise it will still spam.

You should start up a test validator and check logs. It should not report more than once per slot.

self.count_metrics.report_and_reset(&self.id);
self.timing_metrics.report_and_reset(&self.id);
self.error_metrics.report_and_reset(&self.id);
self.slot.swap(0, Ordering::Relaxed);
}
}

fn new(id: u32) -> Self {
Self {
id: id.to_string(),
interval: AtomicInterval::default(),
has_data: AtomicBool::new(false),
slot: AtomicU64::new(0),
count_metrics: ConsumeWorkerCountMetrics::default(),
error_metrics: ConsumeWorkerTransactionErrorMetrics::default(),
timing_metrics: ConsumeWorkerTimingMetrics::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<T: LikeClusterInfo> SchedulerController<T> {
.maybe_report_and_reset_interval(should_report);
self.worker_metrics
.iter()
.for_each(|metrics| metrics.maybe_report_and_reset());
.for_each(|metrics| metrics.maybe_report_and_reset(new_leader_slot));
}

Ok(())
Expand Down
Loading