forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
716ca7f
Report ConsumeWorkerMetrics at slot transitions
ksolana 82b7ff1
only report when there was a slot
ksolana ad06977
reset slot after reporting
ksolana f58a61f
Report slot for the three metrics
ksolana 3a20d04
Pass slot as function parameter
ksolana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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::{ | ||
|
@@ -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) | ||
{ | ||
self.count_metrics.report_and_reset(&self.id); | ||
self.timing_metrics.report_and_reset(&self.id); | ||
self.error_metrics.report_and_reset(&self.id); | ||
/// 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>) { | ||
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, slot); | ||
self.timing_metrics.report_and_reset(&self.id, slot); | ||
self.error_metrics.report_and_reset(&self.id, slot); | ||
self.slot.swap(slot, Ordering::Relaxed); | ||
} | ||
} else if prev_slot_id != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, prev_slot_id); | ||
self.timing_metrics.report_and_reset(&self.id, prev_slot_id); | ||
self.error_metrics.report_and_reset(&self.id, prev_slot_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(), | ||
|
@@ -432,7 +443,7 @@ impl Default for ConsumeWorkerCountMetrics { | |
} | ||
|
||
impl ConsumeWorkerCountMetrics { | ||
fn report_and_reset(&self, id: &str) { | ||
fn report_and_reset(&self, id: &str, slot: u64) { | ||
datapoint_info!( | ||
"banking_stage_worker_counts", | ||
"id" => id, | ||
|
@@ -480,6 +491,11 @@ impl ConsumeWorkerCountMetrics { | |
self.max_prioritization_fees.swap(0, Ordering::Relaxed), | ||
i64 | ||
), | ||
( | ||
"slot", | ||
slot, | ||
i64 | ||
), | ||
); | ||
} | ||
} | ||
|
@@ -498,7 +514,7 @@ struct ConsumeWorkerTimingMetrics { | |
} | ||
|
||
impl ConsumeWorkerTimingMetrics { | ||
fn report_and_reset(&self, id: &str) { | ||
fn report_and_reset(&self, id: &str, slot: u64) { | ||
datapoint_info!( | ||
"banking_stage_worker_timing", | ||
"id" => id, | ||
|
@@ -539,6 +555,11 @@ impl ConsumeWorkerTimingMetrics { | |
self.wait_for_bank_failure_us.swap(0, Ordering::Relaxed), | ||
i64 | ||
), | ||
( | ||
"slot", | ||
slot, | ||
i64 | ||
), | ||
); | ||
} | ||
} | ||
|
@@ -572,7 +593,7 @@ struct ConsumeWorkerTransactionErrorMetrics { | |
} | ||
|
||
impl ConsumeWorkerTransactionErrorMetrics { | ||
fn report_and_reset(&self, id: &str) { | ||
fn report_and_reset(&self, id: &str, slot: u64) { | ||
datapoint_info!( | ||
"banking_stage_worker_error_metrics", | ||
"id" => id, | ||
|
@@ -683,6 +704,11 @@ impl ConsumeWorkerTransactionErrorMetrics { | |
.swap(0, Ordering::Relaxed), | ||
i64 | ||
), | ||
( | ||
"slot", | ||
slot, | ||
i64 | ||
), | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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