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_db_speed_record' #12

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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ enable_execution_duration_record = [
"open_performance_dashboard",
]
enable_test_max_th = ["reth-stages/enable_test_max_th"]
enable_db_speed_record = [
"reth-stages/enable_db_speed_record",
"open_performance_dashboard",
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does enable_db_speed_record rely on other features?


[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] }
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pprof = { version = "0.12", features = ["flamegraph", "frame-pointer", "criterio
default = []
arbitrary = ["revm-primitives/arbitrary", "dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
test-utils = []
enable_db_speed_record = []

[[bench]]
name = "recover_ecdsa_crit"
Expand Down
18 changes: 18 additions & 0 deletions crates/primitives/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ impl Account {
None => KECCAK_EMPTY,
}
}

/// Calculate size of the [Account].
#[cfg(feature = "enable_db_speed_record")]
pub fn size(&self) -> usize {
std::mem::size_of::<u64>() + // Account nonce
std::mem::size_of::<U256>() + // Account balance
if self.has_bytecode() { // Hash of the account's bytecode
std::mem::size_of::<H256>()
} else {
0
}
}
}

/// Bytecode for an account.
Expand Down Expand Up @@ -73,6 +85,12 @@ impl Bytecode {
self.0.hash = code_hash;
self
}

/// Calculates size of the [Bytecode].
#[cfg(feature = "enable_db_speed_record")]
pub fn size(&self) -> usize {
self.bytecode.len()
}
}

impl Deref for Bytecode {
Expand Down
10 changes: 10 additions & 0 deletions crates/primitives/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ pub struct Log {
/// Arbitrary length data.
pub data: Bytes,
}

#[cfg(feature = "enable_db_speed_record")]
impl Log {
/// Calculate size of the [Log].
pub fn size(&self) -> usize {
std::mem::size_of::<Address>() +
std::mem::size_of::<H256>() * self.topics.len() +
self.data.len()
}
}
9 changes: 9 additions & 0 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl Receipt {
pub fn with_bloom(self) -> ReceiptWithBloom {
self.into()
}

/// Calculate size of the [Receipt].
#[cfg(feature = "enable_db_speed_record")]
pub fn size(&self) -> usize {
std::mem::size_of::<u64>() + // cumulative_gas_used
self.logs.iter().map(|v| {
v.size()
}).sum::<usize>()
}
}

impl From<Receipt> for ReceiptWithBloom {
Expand Down
6 changes: 6 additions & 0 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ impl Transaction {
}
}

/// Calculates a heuristic for the in-memory size of the [Transaction].
#[cfg(feature = "enable_db_speed_record")]
pub fn get_size(&self) -> usize {
self.size()
}

/// Calculates a heuristic for the in-memory size of the [Transaction].
#[inline]
fn size(&self) -> usize {
Expand Down
1 change: 1 addition & 0 deletions crates/stages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ finish_after_execution_stage = []
enable_execution_duration_record = ["minstant"]
enable_tps_gas_record = []
enable_test_max_th = []
enable_db_speed_record =["reth-provider/enable_db_speed_record"]

[[bench]]
name = "criterion"
Expand Down
63 changes: 60 additions & 3 deletions crates/stages/src/metrics/listener.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -34,6 +33,11 @@ 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,
},
// /// Revm metric record.
// #[cfg(feature = "enable_opcode_metrics")]
// RevmMetricRecord {
Expand Down Expand Up @@ -64,6 +68,22 @@ pub enum MetricEvent {
/// Gas processed.
gas: u64,
},
/// db speed metric record
#[cfg(feature = "enable_db_speed_record")]
DBSpeedInfo {
/// total time of read header td from db
read_header_td_db_time: u128,
/// total data size of read header td from db
read_header_td_db_size: u64,
/// total time of read block with senders from db
read_block_with_senders_db_time: u128,
/// total data size of read block with senders from db
read_block_with_senders_db_size: u64,
/// time of write to db
write_to_db_time: u128,
/// data size of write to db
write_to_db_size: u64,
},
}

/// Metrics routine that listens to new metric events on the `events_rx` receiver.
Expand Down Expand Up @@ -111,7 +131,11 @@ 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 = "enable_execution_duration_record")]
MetricEvent::ExecutionStageTime {
execute_inner,
Expand Down Expand Up @@ -149,6 +173,39 @@ impl MetricsListener {
.mgas_processed_total
.increment(gas as f64 / MGAS_TO_GAS as f64);
}
#[cfg(feature = "enable_db_speed_record")]
MetricEvent::DBSpeedInfo {
read_header_td_db_time,
read_header_td_db_size,
read_block_with_senders_db_time,
read_block_with_senders_db_size,
write_to_db_time,
write_to_db_size,
} => {
self.sync_metrics
.execution_stage
.read_header_td_db_time
.increment(read_header_td_db_time.try_into().expect("truncation error"));
self.sync_metrics
.execution_stage
.read_header_td_db_size
.increment(read_header_td_db_size);
self.sync_metrics.execution_stage.read_block_with_senders_db_time.increment(
read_block_with_senders_db_time.try_into().expect("truncation error"),
);
self.sync_metrics
.execution_stage
.read_block_with_senders_db_size
.increment(read_block_with_senders_db_size);
self.sync_metrics
.execution_stage
.db_speed_write_to_db_time
.increment(write_to_db_time.try_into().expect("truncation error"));
self.sync_metrics
.execution_stage
.db_speed_write_to_db_size
.increment(write_to_db_size);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/stages/src/metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod listener;
mod sync_metrics;
#[cfg(feature = "enable_execution_duration_record")]
#[cfg(any(feature = "enable_execution_duration_record", feature = "enable_db_speed_record"))]
mod util;

pub use listener::{MetricEvent, MetricEventsSender, MetricsListener};
use sync_metrics::*;
#[cfg(feature = "enable_execution_duration_record")]
#[cfg(any(feature = "enable_execution_duration_record", feature = "enable_db_speed_record"))]
pub(crate) use util::*;
22 changes: 19 additions & 3 deletions crates/stages/src/metrics/sync_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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 @@ -36,12 +35,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 = "enable_tps_gas_record")]
pub(crate) txs_processed_total: Counter,
#[cfg(feature = "open_performance_dashboard")]
/// Time of execute inner.
#[cfg(feature = "enable_execution_duration_record")]
pub(crate) execute_inner_time: Counter,
Expand All @@ -57,4 +54,23 @@ pub(crate) struct ExecutionStageMetrics {
/// 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,
}
50 changes: 49 additions & 1 deletion crates/stages/src/metrics/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(feature = "enable_execution_duration_record")]
use minstant::Instant;
#[cfg(feature = "enable_execution_duration_record")]
use std::time::Duration;

#[cfg(feature = "enable_execution_duration_record")]
#[derive(Debug)]
pub(crate) struct ExecutionDurationRecord {
/// execute inner time recorder
Expand All @@ -20,6 +22,7 @@ pub(crate) struct ExecutionDurationRecord {
pub(crate) write_to_db: Duration,
}

#[cfg(feature = "enable_execution_duration_record")]
impl Default for ExecutionDurationRecord {
fn default() -> Self {
Self {
Expand All @@ -34,6 +37,7 @@ impl Default for ExecutionDurationRecord {
}
}

#[cfg(feature = "enable_execution_duration_record")]
impl ExecutionDurationRecord {
/// start inner time recorder
pub(crate) fn start_inner_time_recorder(&mut self) {
Expand Down Expand Up @@ -69,3 +73,47 @@ impl ExecutionDurationRecord {
self.write_to_db.checked_add(self.time_recorder.elapsed()).expect("overflow");
}
}

#[cfg(feature = "enable_db_speed_record")]
#[derive(Debug, Default)]
pub(crate) struct DbSpeedRecord {
/// time of read header td from db
pub(crate) read_header_td_db_time: u128,
/// data size of read header td from db
pub(crate) read_header_td_db_size: u64,
/// time of read block with senders from db
pub(crate) read_block_with_senders_db_time: u128,
/// data size of read block with senders from db
pub(crate) read_block_with_senders_db_size: u64,
/// time of write to db
pub(crate) write_to_db_time: u128,
/// data size of write to db
pub(crate) write_to_db_size: u64,
}

#[cfg(feature = "enable_db_speed_record")]
impl DbSpeedRecord {
/// add time of write to db
pub(crate) fn add_read_header_td_db_time(&mut self, add_time: u128) {
self.read_header_td_db_time =
self.read_header_td_db_time.checked_add(add_time).expect("overflow");
}

/// add time of write to db
pub(crate) fn add_read_header_td_db_size(&mut self, add_size: u64) {
self.read_header_td_db_size =
self.read_header_td_db_size.checked_add(add_size).expect("overflow");
}

/// add time of write to db
pub(crate) fn add_read_block_with_senders_db_time(&mut self, add_time: u128) {
self.read_block_with_senders_db_time =
self.read_block_with_senders_db_time.checked_add(add_time).expect("overflow");
}

/// add time of write to db
pub(crate) fn add_read_block_with_senders_db_size(&mut self, add_size: u64) {
self.read_block_with_senders_db_size =
self.read_block_with_senders_db_size.checked_add(add_size).expect("overflow");
}
}
Loading
Loading