Skip to content

Commit

Permalink
feat(vm_executor): Add new histogram metric for gas per tx in vm_exec…
Browse files Browse the repository at this point in the history
…utor

- The existing metric is a histogram of rates. That's a little difficult
  to extract useful throughput numbers out of with the notable exception
  of efficiency.
- Exporting this metric to let the consumer do their own: rate/anomoly
  calculation on gas/tx, ratio of gas burn for failed tx, etc.
  • Loading branch information
doyleish committed Oct 31, 2024
1 parent 42f177a commit d33dc1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/lib/vm_executor/src/batch/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,23 @@ where
let elapsed = latency.observe();

if !res.tx_result.result.is_failed() {
let gas_per_nanosecond =
res.tx_result.statistics.computational_gas_used as f64 / elapsed.as_nanos() as f64;
let gas_used = res.tx_result.statistics.computational_gas_used;
EXECUTOR_METRICS
.computational_gas_per_nanosecond
.observe(gas_per_nanosecond);
.observe(gas_used as f64 / elapsed.as_nanos() as f64);
EXECUTOR_METRICS
.computational_gas_used
.observe(gas_used as usize);
} else {
// The amount of computational gas paid for failed transactions is hard to get
// but comparing to the gas limit makes sense, since we can burn all gas
// if some kind of failure is a DDoS vector otherwise.
EXECUTOR_METRICS
.failed_tx_gas_limit_per_nanosecond
.observe(tx_gas_limit as f64 / elapsed.as_nanos() as f64);
EXECUTOR_METRICS
.failed_tx_gas_limit
.observe(tx_gas_limit as usize);
}
Ok(res)
}
Expand Down
10 changes: 10 additions & 0 deletions core/lib/vm_executor/src/batch/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const GAS_PER_NANOSECOND_BUCKETS: Buckets = Buckets::values(&[
0.01, 0.03, 0.1, 0.3, 0.5, 0.75, 1., 1.5, 3., 5., 10., 20., 50.,
]);

const GAS_USED_BUCKETS: Buckets = Buckets::values(&[
10000., 25000., 45000., 70000., 100000., 150000., 225000., 350000., 500000.,
]);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
#[metrics(label = "stage", rename_all = "snake_case")]
pub(super) enum TxExecutionStage {
Expand All @@ -37,8 +41,14 @@ pub(super) struct ExecutorMetrics {
pub batch_executor_command_response_time: Family<ExecutorCommand, Histogram<Duration>>,
#[metrics(buckets = GAS_PER_NANOSECOND_BUCKETS)]
pub computational_gas_per_nanosecond: Histogram<f64>,
/// Computational gas used, per transaction.
#[metrics(buckets = GAS_USED_BUCKETS)]
pub computational_gas_used: Histogram<usize>,
#[metrics(buckets = GAS_PER_NANOSECOND_BUCKETS)]
pub failed_tx_gas_limit_per_nanosecond: Histogram<f64>,
/// Gas limit, per failed transaction.
#[metrics(buckets = GAS_USED_BUCKETS)]
pub failed_tx_gas_limit: Histogram<usize>,
/// Cumulative latency of interacting with the storage when executing a transaction
/// in the batch executor.
#[metrics(buckets = Buckets::LATENCIES)]
Expand Down

0 comments on commit d33dc1e

Please sign in to comment.