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

add feature 'enable_tps_gas_record' #7

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ enable_cache_record = [
"reth-stages/enable_cache_record",
"reth-rpc/enable_cache_record",
]
enable_tps_gas_record = [
"reth-stages/enable_tps_gas_record",
"open_performance_dashboard",
]
finish_after_execution_stage = ["reth-stages/finish_after_execution_stage"]
enable_execution_duration_record = [
"reth-stages/enable_execution_duration_record",
Expand Down
1 change: 1 addition & 0 deletions crates/stages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enable_opcode_metrics = ["reth-provider/enable_opcode_metrics"]
enable_cache_record = ["reth-provider/enable_cache_record"]
finish_after_execution_stage = []
enable_execution_duration_record = []
enable_tps_gas_record = []

[[bench]]
name = "criterion"
Expand Down
40 changes: 19 additions & 21 deletions crates/stages/src/metrics/listener.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::metrics::SyncMetrics;
#[cfg(feature = "enable_tps_gas_record")]
use reth_primitives::constants::MGAS_TO_GAS;
use reth_primitives::{
constants::MGAS_TO_GAS,
stage::{StageCheckpoint, StageId},
BlockNumber,
};
Expand Down Expand Up @@ -39,17 +40,6 @@ pub enum MetricEvent {
/// If specified, `entities_total` metric is updated.
max_block_number: Option<BlockNumber>,
},
/// Execution stage processed some amount of gas.
ExecutionStageGas {
/// Gas processed.
gas: u64,
},
/// Execution stage processed some amount of txs.
#[cfg(feature = "open_performance_dashboard")]
ExecutionStageTxs {
/// Txs processed.
txs: u64,
},
// /// Revm metric record.
// #[cfg(feature = "enable_opcode_metrics")]
// RevmMetricRecord {
Expand All @@ -72,6 +62,14 @@ pub enum MetricEvent {
/// time of write to db
write_to_db: u64,
},
/// Execution stage processed some amount of txs and gas in a block.
#[cfg(feature = "enable_tps_gas_record")]
BlockTpsAndGas {
/// Txs processed.
txs: u64,
/// Gas processed.
gas: u64,
},
}

/// Metrics routine that listens to new metric events on the `events_rx` receiver.
Expand Down Expand Up @@ -119,15 +117,7 @@ impl MetricsListener {
stage_metrics.entities_total.set(total as f64);
}
}
MetricEvent::ExecutionStageGas { gas } => self
.sync_metrics
.execution_stage
.mgas_processed_total
.increment(gas as f64 / MGAS_TO_GAS as f64),
#[cfg(feature = "open_performance_dashboard")]
MetricEvent::ExecutionStageTxs { txs } => {
self.sync_metrics.execution_stage.txs_processed_total.increment(txs)
}

#[cfg(feature = "enable_execution_duration_record")]
MetricEvent::ExecutionStageTime {
execute_inner,
Expand Down Expand Up @@ -159,6 +149,14 @@ impl MetricsListener {
.write_to_db_time
.increment(convert_to_nanoseconds(write_to_db, cpu_frequency));
}
#[cfg(feature = "enable_tps_gas_record")]
MetricEvent::BlockTpsAndGas { txs, gas } => {
self.sync_metrics.execution_stage.txs_processed_total.increment(txs);
self.sync_metrics
.execution_stage
.mgas_processed_total
.increment(gas as f64 / MGAS_TO_GAS as f64);
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/stages/src/metrics/sync_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::collections::HashMap;
#[derive(Debug, Default)]
pub(crate) struct SyncMetrics {
pub(crate) stages: HashMap<StageId, StageMetrics>,
#[cfg(feature = "open_performance_dashboard")]
pub(crate) execution_stage: ExecutionStageMetrics,
}

Expand Down Expand Up @@ -35,9 +36,10 @@ pub(crate) struct StageMetrics {
#[metrics(scope = "sync.execution")]
pub(crate) struct ExecutionStageMetrics {
/// The total amount of gas processed (in millions).
#[cfg(feature = "enable_tps_gas_record")]
pub(crate) mgas_processed_total: Gauge,
/// The total amount of transactions processed.
#[cfg(feature = "open_performance_dashboard")]
#[cfg(feature = "enable_tps_gas_record")]
pub(crate) txs_processed_total: Counter,
#[cfg(feature = "open_performance_dashboard")]
/// Time of execute inner.
Expand Down
13 changes: 9 additions & 4 deletions crates/stages/src/stages/execution.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#[cfg(feature = "enable_execution_duration_record")]
use crate::ExecutionDurationRecord;
#[cfg(feature = "open_performance_dashboard")]
use crate::MetricEvent;
use crate::{
stages::MERKLE_STAGE_DEFAULT_CLEAN_THRESHOLD, ExecInput, ExecOutput, MetricEvent,
MetricEventsSender, Stage, StageError, UnwindInput, UnwindOutput,
stages::MERKLE_STAGE_DEFAULT_CLEAN_THRESHOLD, ExecInput, ExecOutput, MetricEventsSender, Stage,
StageError, UnwindInput, UnwindOutput,
};
use num_traits::Zero;
use reth_db::{
Expand Down Expand Up @@ -170,9 +172,12 @@ impl<EF: ExecutorFactory> ExecutionStage<EF> {
duration_record.add_execute_tx();

// Gas and txs metrics
#[cfg(feature = "enable_tps_gas_record")]
if let Some(metrics_tx) = &mut self.metrics_tx {
let _ =
metrics_tx.send(MetricEvent::ExecutionStageGas { gas: block.header.gas_used });
let _ = metrics_tx.send(MetricEvent::BlockTpsAndGas {
txs: block.body.len() as u64,
gas: block.header.gas_used,
});
}

// Merge state changes
Expand Down