feat: log throughput in execution stage (#9253)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Park Smith
2024-07-05 13:20:52 +01:00
committed by GitHub
parent c13af1e6d1
commit 08feab1a56
2 changed files with 29 additions and 6 deletions

View File

@@ -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");
}
}

View File

@@ -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 _ =