mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-03 11:34:57 -05:00
feat: log throughput in execution stage (#9253)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -18,11 +18,11 @@ pub const GIGAGAS: u64 = MEGAGAS * 1_000;
|
||||
pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String {
|
||||
let gas_per_second = gas as f64 / execution_duration.as_secs_f64();
|
||||
if gas_per_second < MEGAGAS as f64 {
|
||||
format!("{:.} Kgas/second", gas_per_second / KILOGAS as f64)
|
||||
format!("{:.2} Kgas/second", gas_per_second / KILOGAS as f64)
|
||||
} else if gas_per_second < GIGAGAS as f64 {
|
||||
format!("{:.} Mgas/second", gas_per_second / MEGAGAS as f64)
|
||||
format!("{:.2} Mgas/second", gas_per_second / MEGAGAS as f64)
|
||||
} else {
|
||||
format!("{:.} Ggas/second", gas_per_second / GIGAGAS as f64)
|
||||
format!("{:.2} Ggas/second", gas_per_second / GIGAGAS as f64)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ mod tests {
|
||||
let duration = Duration::from_secs(1);
|
||||
let gas = 100_000;
|
||||
let throughput = format_gas_throughput(gas, duration);
|
||||
assert_eq!(throughput, "100 Kgas/second");
|
||||
assert_eq!(throughput, "100.00 Kgas/second");
|
||||
|
||||
let gas = 100_000_000;
|
||||
let throughput = format_gas_throughput(gas, duration);
|
||||
assert_eq!(throughput, "100 Mgas/second");
|
||||
assert_eq!(throughput, "100.00 Mgas/second");
|
||||
|
||||
let gas = 100_000_000_000;
|
||||
let throughput = format_gas_throughput(gas, duration);
|
||||
assert_eq!(throughput, "100 Ggas/second");
|
||||
assert_eq!(throughput, "100.00 Ggas/second");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,6 +233,13 @@ where
|
||||
|
||||
let mut fetch_block_duration = Duration::default();
|
||||
let mut execution_duration = Duration::default();
|
||||
|
||||
let mut last_block = start_block;
|
||||
let mut last_execution_duration = Duration::default();
|
||||
let mut last_cumulative_gas = 0;
|
||||
let mut last_log_instant = Instant::now();
|
||||
let log_duration = Duration::from_secs(10);
|
||||
|
||||
debug!(target: "sync::stages::execution", start = start_block, end = max_block, "Executing range");
|
||||
|
||||
// Execute block range
|
||||
@@ -271,6 +278,22 @@ where
|
||||
})?;
|
||||
execution_duration += execute_start.elapsed();
|
||||
|
||||
// Log execution throughput
|
||||
if last_log_instant.elapsed() >= log_duration {
|
||||
info!(
|
||||
target: "sync::stages::execution",
|
||||
start = last_block,
|
||||
end = block_number,
|
||||
throughput = format_gas_throughput(cumulative_gas - last_cumulative_gas, execution_duration - last_execution_duration),
|
||||
"Executed block range"
|
||||
);
|
||||
|
||||
last_block = block_number + 1;
|
||||
last_execution_duration = execution_duration;
|
||||
last_cumulative_gas = cumulative_gas;
|
||||
last_log_instant = Instant::now();
|
||||
}
|
||||
|
||||
// Gas metrics
|
||||
if let Some(metrics_tx) = &mut self.metrics_tx {
|
||||
let _ =
|
||||
|
||||
Reference in New Issue
Block a user