diff --git a/Cargo.lock b/Cargo.lock index 79f78b7e3114..58601e40fde0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5226,7 +5226,6 @@ dependencies = [ "metrics-process", "metrics-util", "minstant", - "parking_lot 0.12.1", "pin-project", "pretty_assertions", "proptest", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 5a3ead564bd8..5891f06b05f3 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -123,7 +123,6 @@ boyer-moore-magiclen = "0.2.16" minstant = { version = "0.1.3", optional = true } -parking_lot = { version = "0.12", optional = true } [target.'cfg(not(windows))'.dependencies] jemallocator = { version = "0.5.0", optional = true } @@ -142,8 +141,6 @@ min-debug-logs = ["tracing/release_max_level_debug"] min-trace-logs = ["tracing/release_max_level_trace"] open_performance_dashboard = [ "reth-stages/open_performance_dashboard", - "minstant", - "parking_lot", ] enable_opcode_metrics = [ "reth-revm/enable_opcode_metrics", @@ -166,6 +163,7 @@ enable_cache_record = [ enable_tps_gas_record = [ "reth-stages/enable_tps_gas_record", "open_performance_dashboard", + "minstant", ] finish_after_execution_stage = ["reth-stages/finish_after_execution_stage"] enable_execution_duration_record = [ diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 083f24696664..3d2f569713b4 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -83,7 +83,6 @@ use tracing::*; #[cfg(feature = "open_performance_dashboard")] use crate::performance_metrics::DashboardListener; -// use crate::performance_metrics::{DashboardEventsSender, DashboardListener}; pub mod cl_events; pub mod events; @@ -251,11 +250,6 @@ impl NodeCommand { self.start_metrics_endpoint(Arc::clone(&db)).await?; - #[cfg(feature = "open_performance_dashboard")] - { - start_performance_dashboard(&ctx.task_executor); - } - debug!(target: "reth::cli", chain=%self.chain.chain, genesis=?self.chain.genesis_hash(), "Initializing genesis"); let genesis_hash = init_genesis(db.clone(), self.chain.clone())?; @@ -947,25 +941,6 @@ async fn run_network_until_shutdown( } } -#[cfg(feature = "open_performance_dashboard")] -fn start_performance_dashboard(task_executor: &TaskExecutor) { - use crate::performance_metrics::{metric_handler::*, metric_recoder::*, metric_storage::*}; - - let storage = Arc::new(PerformanceDashboardMetricStorage::default()); - - let recorder = PerformanceDashboardRecorder::new(storage.clone()); - metrics::set_boxed_recorder(Box::new(recorder)).unwrap(); - - let mut performance_dashboard_handler = PerformanceDashboardMetricHandler::new(storage); - - task_executor.spawn_critical( - "performance dashboard", - Box::pin(async move { - performance_dashboard_handler.run(300).await; - }), - ); -} - #[cfg(test)] mod tests { use super::*; diff --git a/bin/reth/src/performance_metrics/dashboard_display.rs b/bin/reth/src/performance_metrics/dashboard_display.rs index 11c3c0c14c2a..567675b4668d 100644 --- a/bin/reth/src/performance_metrics/dashboard_display.rs +++ b/bin/reth/src/performance_metrics/dashboard_display.rs @@ -80,7 +80,7 @@ impl OpcodeStats { // println!("Total Count : {:>20}", self.total_count); // println!("Total Time (s) : {:>20.2}", self.total_duration.as_secs_f64()); // println!( - // "Ave Cost (ns) : {:>20.1}", + // "Avg Cost (ns) : {:>20.1}", // self.total_duration.as_nanos() as f64 / self.total_count as f64 // ); println!(""); @@ -326,8 +326,9 @@ impl ExecutionDurationDisplayer { pub(crate) fn print(&self) { self.excution_duration_record.print("===============================Metric of execution duration=========================================================="); - let pure_record = self.excution_duration_record.pure_record(); - pure_record.print("===============================Metric of pure execution duration=========================================================="); + // let pure_record = self.excution_duration_record.pure_record(); + // pure_record.print("===============================Metric of pure execution + // duration=========================================================="); } } @@ -378,7 +379,7 @@ impl CacheDBRecordDisplayer { let col_percentage_len = 20; println!( - "{:col_funciotns_len$}{:col_times_len$}{:col_percentage_len$.3}", + "{:col_funciotns_len$}{:>col_times_len$}{:>col_percentage_len$.3}", function, times, percentiles ); } diff --git a/bin/reth/src/performance_metrics/dashboard_listener.rs b/bin/reth/src/performance_metrics/dashboard_listener.rs index b8ada383b9f8..25c28a0bd04b 100644 --- a/bin/reth/src/performance_metrics/dashboard_listener.rs +++ b/bin/reth/src/performance_metrics/dashboard_listener.rs @@ -11,8 +11,6 @@ use reth_stages::MetricEvent; #[cfg(feature = "enable_opcode_metrics")] use super::dashboard_display::RevmMetricTimeDisplayer; -// #[cfg(feature = "enable_opcode_metrics")] -// use revm_utils::types::RevmMetricRecord; #[cfg(feature = "enable_execution_duration_record")] use super::dashboard_display::ExecutionDurationDisplayer; diff --git a/bin/reth/src/performance_metrics/dashboard_opcode.rs b/bin/reth/src/performance_metrics/dashboard_opcode.rs index 413aea1ca185..14cd50148259 100644 --- a/bin/reth/src/performance_metrics/dashboard_opcode.rs +++ b/bin/reth/src/performance_metrics/dashboard_opcode.rs @@ -1,5 +1,4 @@ use revm_interpreter::opcode::*; -// use std::collections::HashMap; pub(crate) const OPCODE_NUMBER: usize = std::u8::MAX as usize + 1; diff --git a/bin/reth/src/performance_metrics/metric_handler.rs b/bin/reth/src/performance_metrics/metric_handler.rs deleted file mode 100644 index 11cd801b072f..000000000000 --- a/bin/reth/src/performance_metrics/metric_handler.rs +++ /dev/null @@ -1,80 +0,0 @@ -use super::metric_storage::{MetricsStorage, PerformanceDashboardMetricStorage}; -use std::sync::Arc; - -use std::{ - ops::{Div, Mul}, - time::Duration, -}; -use tokio::time::sleep; -use tracing::*; - -pub(crate) struct PerformanceDashboardMetricHandler { - storage: Arc, - pre_snapshot: Option, - cnt: u64, -} - -impl PerformanceDashboardMetricHandler { - pub(crate) fn new(storage: Arc) -> Self { - Self { storage, cnt: 0, pre_snapshot: None } - } - - pub(crate) async fn run(&mut self, interval: u64) { - let mut pre = minstant::Instant::now(); - loop { - { - let snapshot = self.storage.snapshot(); - let now = minstant::Instant::now(); - let elapsed_ns = now.checked_duration_since(pre).expect("overflow").as_nanos(); - pre = now; - - if let Some(pre_snapshot) = self.pre_snapshot.take() { - // 1. calculate tps - let delta_txs: u128 = snapshot - .total_txs_processed - .checked_sub(pre_snapshot.total_txs_processed) - .expect("overflow") - .into(); - let tps = delta_txs.mul(1000_000_000).div(elapsed_ns); - - // 2. calculate mGas/s - let delta_mgas = snapshot.total_mgas_used - pre_snapshot.total_mgas_used; - let mgas_ps = delta_mgas.mul(1000_000_000 as f64).div(elapsed_ns as f64); - - info!(target: "performance_dashboard_metrics.sync_stage.execution", "tps =====> {:?}", tps); - info!(target: "performance_dashboard_metrics.sync_stage.execution", "mGas/s =====> {:?}", mgas_ps); - self.cnt += 1; - - // 3. total - let execute_inner_time = snapshot.execute_inner_time; - if execute_inner_time != 0 { - info!(target: "performance_dashboard_metrics.sync_stage.execution", "execute inner time =====> {:?}", execute_inner_time); - } - let read_block_info_time = snapshot.read_block_info_time; - if read_block_info_time != 0 { - info!(target: "performance_dashboard_metrics.sync_stage.execution", "total read block info time =====> {:?}", read_block_info_time); - } - let revm_execute_time = snapshot.revm_execute_time; - if revm_execute_time != 0 { - info!(target: "performance_dashboard_metrics.sync_stage.execution", "total revm execute time =====> {:?}", revm_execute_time); - } - let post_process_time = snapshot.post_process_time; - if post_process_time != 0 { - info!(target: "performance_dashboard_metrics.sync_stage.execution", "total post process time =====> {:?}", post_process_time); - } - let write_to_db_time = snapshot.write_to_db_time; - if write_to_db_time != 0 { - info!(target: "performance_dashboard_metrics.sync_stage.execution", "total write to db time =====> {:?}", write_to_db_time); - } - } - - self.record(snapshot); - } - sleep(Duration::from_secs(interval)).await; - } - } - - fn record(&mut self, snapshot: MetricsStorage) { - self.pre_snapshot = Some(snapshot); - } -} diff --git a/bin/reth/src/performance_metrics/metric_recoder.rs b/bin/reth/src/performance_metrics/metric_recoder.rs deleted file mode 100644 index f96b5b512d96..000000000000 --- a/bin/reth/src/performance_metrics/metric_recoder.rs +++ /dev/null @@ -1,122 +0,0 @@ -use super::metric_storage::PerformanceDashboardMetricStorage; -use metrics::{ - Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, KeyName, Recorder, - SharedString, Unit, -}; -use std::sync::Arc; -use tracing::*; - -struct Handle { - key: Key, - storage: Arc, -} - -impl<'a> Handle { - fn new(key: Key, storage: Arc) -> Handle { - Handle { key, storage } - } -} - -impl CounterFn for Handle { - fn increment(&self, value: u64) { - match self.key.name() { - "sync.execution.txs_processed_total" => { - let mut guard = self.storage.total_txs_processed.lock(); - *guard = (*guard).checked_add(value).expect("counter txs_processed_total overflow"); - } - "sync.execution.execute_inner_time" => { - let mut guard = self.storage.execute_inner_time.lock(); - *guard = (*guard).checked_add(value).expect("counter execute_inner_time overflow"); - } - "sync.execution.read_block_info_time" => { - let mut guard = self.storage.read_block_info_time.lock(); - *guard = - (*guard).checked_add(value).expect("counter read_block_info_time overflow"); - } - "sync.execution.revm_execute_time" => { - let mut guard = self.storage.revm_execute_time.lock(); - *guard = (*guard).checked_add(value).expect("counter revm_execute_time overflow"); - } - "sync.execution.post_process_time" => { - let mut guard = self.storage.post_process_time.lock(); - *guard = (*guard).checked_add(value).expect("counter post_process_time overflow"); - } - "sync.execution.write_to_db_time" => { - let mut guard = self.storage.write_to_db_time.lock(); - *guard = (*guard).checked_add(value).expect("counter write_to_db_time overflow"); - } - _ => {} - } - } - - fn absolute(&self, _value: u64) {} -} - -impl GaugeFn for Handle { - fn increment(&self, value: f64) { - match self.key.name() { - "sync.execution.mgas_processed_total" => { - let mut guard = self.storage.total_mgas_used.lock(); - *guard += value; - } - _ => {} - } - } - - fn decrement(&self, _value: f64) {} - fn set(&self, _value: f64) {} -} - -impl HistogramFn for Handle { - fn record(&self, _value: f64) {} -} - -pub(crate) struct PerformanceDashboardRecorder { - storage: Arc, -} -impl PerformanceDashboardRecorder { - pub(crate) fn new(storage: Arc) -> Self { - Self { storage } - } -} - -impl Recorder for PerformanceDashboardRecorder { - fn describe_counter(&self, key_name: KeyName, unit: Option, description: SharedString) { - info!(target: "performance_dashboard_metrics", - "(counter) registered key {} with unit {:?} and description {:?}", - key_name.as_str(), - unit, - description - ); - } - - fn describe_gauge(&self, key_name: KeyName, unit: Option, description: SharedString) { - info!(target: "performance_dashboard_metrics", - "(gauge) registered key {} with unit {:?} and description {:?}", - key_name.as_str(), - unit, - description - ); - } - - fn describe_histogram(&self, key_name: KeyName, unit: Option, description: SharedString) { - info!(target: "performance_dashboard_metrics", - "(histogram) registered key {} with unit {:?} and description {:?}", - key_name.as_str(), - unit, - description - ); - } - - fn register_counter(&self, key: &Key) -> Counter { - Counter::from_arc(Arc::new(Handle::new(key.clone(), self.storage.clone()))) - } - - fn register_gauge(&self, key: &Key) -> Gauge { - Gauge::from_arc(Arc::new(Handle::new(key.clone(), self.storage.clone()))) - } - - fn register_histogram(&self, key: &Key) -> Histogram { - Histogram::from_arc(Arc::new(Handle::new(key.clone(), self.storage.clone()))) - } -} diff --git a/bin/reth/src/performance_metrics/metric_storage.rs b/bin/reth/src/performance_metrics/metric_storage.rs deleted file mode 100644 index 23e13508370d..000000000000 --- a/bin/reth/src/performance_metrics/metric_storage.rs +++ /dev/null @@ -1,78 +0,0 @@ -use parking_lot::Mutex; -use std::sync::Arc; - -#[derive(Debug, Clone, Default)] -pub(crate) struct PerformanceDashboardMetricStorage { - pub(crate) total_mgas_used: Arc>, - pub(crate) total_txs_processed: Arc>, - pub(crate) execute_inner_time: Arc>, - pub(crate) read_block_info_time: Arc>, - pub(crate) revm_execute_time: Arc>, - pub(crate) post_process_time: Arc>, - pub(crate) write_to_db_time: Arc>, -} -impl PerformanceDashboardMetricStorage { - pub(crate) fn snapshot(&self) -> MetricsStorage { - MetricsStorage::from(self) - } -} - -#[derive(Debug)] -pub(crate) struct MetricsStorage { - pub(crate) total_mgas_used: f64, - pub(crate) total_txs_processed: u64, - pub(crate) execute_inner_time: u64, - pub(crate) read_block_info_time: u64, - pub(crate) revm_execute_time: u64, - pub(crate) post_process_time: u64, - pub(crate) write_to_db_time: u64, -} - -impl From<&PerformanceDashboardMetricStorage> for MetricsStorage { - fn from(storage: &PerformanceDashboardMetricStorage) -> Self { - let total_mgas_used = { - let guard = storage.total_mgas_used.lock(); - *guard - }; - - let total_txs_processed = { - let guard = storage.total_txs_processed.lock(); - *guard - }; - - let execute_inner_time = { - let guard = storage.execute_inner_time.lock(); - *guard - }; - - let read_block_info_time = { - let guard = storage.read_block_info_time.lock(); - *guard - }; - - let revm_execute_time = { - let guard = storage.revm_execute_time.lock(); - *guard - }; - - let post_process_time = { - let guard = storage.post_process_time.lock(); - *guard - }; - - let write_to_db_time = { - let guard = storage.write_to_db_time.lock(); - *guard - }; - - Self { - total_mgas_used, - total_txs_processed, - execute_inner_time, - read_block_info_time, - revm_execute_time, - post_process_time, - write_to_db_time, - } - } -} diff --git a/bin/reth/src/performance_metrics/mod.rs b/bin/reth/src/performance_metrics/mod.rs index 598a88178d8d..b30919e014fd 100644 --- a/bin/reth/src/performance_metrics/mod.rs +++ b/bin/reth/src/performance_metrics/mod.rs @@ -1,7 +1,3 @@ -pub(crate) mod metric_handler; -pub(crate) mod metric_recoder; -pub(crate) mod metric_storage; - mod dashboard_display; mod dashboard_listener; #[cfg(feature = "enable_opcode_metrics")] diff --git a/crates/stages/src/metrics/listener.rs b/crates/stages/src/metrics/listener.rs index 7c91c1992f9d..65e7689618c5 100644 --- a/crates/stages/src/metrics/listener.rs +++ b/crates/stages/src/metrics/listener.rs @@ -46,14 +46,6 @@ pub enum MetricEvent { /// Gas processed. gas: u64, }, - // /// Revm metric record. - // #[cfg(feature = "enable_opcode_metrics")] - // RevmMetricRecord { - // /// Revm metric record. - // record: RevmMetricRecord, - // /// size of cacheDb. - // cachedb_size: usize, - // }, /// Execution stage processed . #[cfg(feature = "enable_execution_duration_record")] ExecutionStageTime { diff --git a/crates/stages/src/metrics/sync_metrics.rs b/crates/stages/src/metrics/sync_metrics.rs index 1f1cf95d89f1..22c648547e1d 100644 --- a/crates/stages/src/metrics/sync_metrics.rs +++ b/crates/stages/src/metrics/sync_metrics.rs @@ -34,41 +34,4 @@ pub(crate) struct StageMetrics { pub(crate) struct ExecutionStageMetrics { /// The total amount of gas processed (in millions). pub(crate) mgas_processed_total: Gauge, - // /// The total amount of transactions processed. - // #[cfg(feature = "enable_tps_gas_record")] - // pub(crate) txs_processed_total: Counter, - // /// Time of execute inner. - // #[cfg(feature = "enable_execution_duration_record")] - // pub(crate) execute_inner_time: Counter, - // /// Time of read block info. - // #[cfg(feature = "enable_execution_duration_record")] - // pub(crate) read_block_info_time: Counter, - // /// Time of revm execute tx. - // #[cfg(feature = "enable_execution_duration_record")] - // pub(crate) revm_execute_time: Counter, - // /// Post process time. - // #[cfg(feature = "enable_execution_duration_record")] - // pub(crate) post_process_time: Counter, - // /// Time of write to db. - // #[cfg(feature = "enable_execution_duration_record")] - // pub(crate) write_to_db_time: Counter, - - // /// total time of read header td from db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) read_header_td_db_time: Counter, - // /// total data size of read header td from db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) read_header_td_db_size: Counter, - // /// total time of read block with senders from db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) read_block_with_senders_db_time: Counter, - // /// total data size of read block with senders from db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) read_block_with_senders_db_size: Counter, - // /// time of write to db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) db_speed_write_to_db_time: Counter, - // /// data size of write to db - // #[cfg(feature = "enable_db_speed_record")] - // pub(crate) db_speed_write_to_db_size: Counter, } diff --git a/crates/stages/src/metrics/util.rs b/crates/stages/src/metrics/util.rs index ab8613db533f..5952603ea943 100644 --- a/crates/stages/src/metrics/util.rs +++ b/crates/stages/src/metrics/util.rs @@ -165,29 +165,31 @@ impl ExecutionDurationRecord { let write_to_db_pct = write_to_db_time / execute_inner_time * 100.0; let total_pct = read_block_pct + execute_tx_pct + process_state_pct + write_to_db_pct; - let time_decimal_place = 6; + let time_decimal_place = 3; let pct_decimal_place = 3; + let col_len = 15; println!(); println!("{}", header); + println!("Cat. Time (h) Time (%)"); println!( - "total : {:.time_decimal_place$}, percentage: {:.pct_decimal_place$}", + "total {:>col_len$.time_decimal_place$} {:>col_len$.pct_decimal_place$}", execute_inner_time, total_pct ); println!( - "fetching_blocks : {:.time_decimal_place$}, percentage: {:.pct_decimal_place$}", + "fetching_blocks {:>col_len$.time_decimal_place$} {:>col_len$.pct_decimal_place$}", read_block_time, read_block_pct ); println!( - "execution : {:.time_decimal_place$}, percentage: {:.pct_decimal_place$}", + "execution {:>col_len$.time_decimal_place$} {:>col_len$.pct_decimal_place$}", execute_tx_time, execute_tx_pct ); println!( - "process_state : {:.time_decimal_place$}, percentage: {:.pct_decimal_place$}", + "process_state {:>col_len$.time_decimal_place$} {:>col_len$.pct_decimal_place$}", process_state_time, process_state_pct ); println!( - "write_to_db : {:.time_decimal_place$}, percentage: {:.pct_decimal_place$}", + "write_to_db {:>col_len$.time_decimal_place$} {:>col_len$.pct_decimal_place$}", write_to_db_time, write_to_db_pct ); println!(); @@ -377,9 +379,12 @@ impl DbSpeedRecord { let write_to_db_rate = write_to_db_size / write_to_db_time; println!("Cat. Size (MBytes) Time (s) Rate (MBytes/s)"); - println! {"{:col_len$}{:col_len$.3}{:col_len$.3}{:col_len$.3}", "Read header td ", read_header_td_size, read_header_td_time, read_header_td_rate}; - println! {"{:col_len$}{:col_len$.3}{:col_len$.3}{:col_len$.3}", "Read header with sender", read_block_with_senders_size, read_block_with_senders_time, read_block_with_senders_rate}; - println! {"{:col_len$}{:col_len$.3}{:col_len$.3}{:col_len$.3}", "Write to db ", write_to_db_size, write_to_db_time, write_to_db_rate}; + println! {"{:col_len$}{:>col_len$.3}{:>col_len$.3}{:>col_len$.3}", "Read header td ", + read_header_td_size, read_header_td_time, read_header_td_rate}; + println! {"{:col_len$}{:>col_len$.3}{:>col_len$.3}{:>col_len$.3}", "Read header with sender", + read_block_with_senders_size, read_block_with_senders_time, read_block_with_senders_rate}; + println! {"{:col_len$}{:>col_len$.3}{:>col_len$.3}{:>col_len$.3}", "Write to db ", + write_to_db_size, write_to_db_time, write_to_db_rate}; println!(); }