From c0cbb6a473a7c602a88b33fa8d6f6fa63e8b8dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Vincent?= <28714795+leovct@users.noreply.github.com> Date: Tue, 9 May 2023 15:52:20 +0200 Subject: [PATCH] feat(txpool): add sub-pools length and size metrics (#2598) Co-authored-by: Matthias Seitz --- crates/transaction-pool/src/metrics.rs | 17 ++++++++++++++++- crates/transaction-pool/src/pool/txpool.rs | 14 ++++++++++++++ docs/design/metrics.md | 8 +++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/transaction-pool/src/metrics.rs b/crates/transaction-pool/src/metrics.rs index f04e07ed5..f5bc2f04d 100644 --- a/crates/transaction-pool/src/metrics.rs +++ b/crates/transaction-pool/src/metrics.rs @@ -1,6 +1,6 @@ //! Transaction pool metrics. -use metrics::Counter; +use metrics::{Counter, Gauge}; use reth_metrics_derive::Metrics; /// Transaction pool metrics @@ -13,4 +13,19 @@ pub struct TxPoolMetrics { pub(crate) invalid_transactions: Counter, /// Number of removed transactions from the pool pub(crate) removed_transactions: Counter, + + /// Number of transactions in the pending sub-pool + pub(crate) pending_pool_transactions: Gauge, + /// Total amount of memory used by the transactions in the pending sub-pool in bytes + pub(crate) pending_pool_size_bytes: Gauge, + + /// Number of transactions in the basefee sub-pool + pub(crate) basefee_pool_transactions: Gauge, + /// Total amount of memory used by the transactions in the basefee sub-pool in bytes + pub(crate) basefee_pool_size_bytes: Gauge, + + /// Number of transactions in the queued sub-pool + pub(crate) queued_pool_transactions: Gauge, + /// Total amount of memory used by the transactions in the queued sub-pool in bytes + pub(crate) queued_pool_size_bytes: Gauge, } diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index b44e56290..faa13e4cd 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -253,9 +253,23 @@ impl TxPool { // Process the sub-pool updates let UpdateOutcome { promoted, discarded } = self.process_updates(updates); + // update the metrics after the update + self.update_size_metrics(); + OnNewCanonicalStateOutcome { block_hash, mined: mined_transactions, promoted, discarded } } + /// Update sub-pools size metrics. + pub(crate) fn update_size_metrics(&mut self) { + let stats = self.size(); + self.metrics.pending_pool_transactions.set(stats.pending as f64); + self.metrics.pending_pool_size_bytes.set(stats.pending_size as f64); + self.metrics.basefee_pool_transactions.set(stats.basefee as f64); + self.metrics.basefee_pool_size_bytes.set(stats.basefee_size as f64); + self.metrics.queued_pool_transactions.set(stats.queued as f64); + self.metrics.queued_pool_size_bytes.set(stats.queued_size as f64); + } + /// Adds the transaction into the pool. /// /// This pool consists of two three-pools: `Queued`, `Pending` and `BaseFee`. diff --git a/docs/design/metrics.md b/docs/design/metrics.md index a0b9f6ad3..38e68a4de 100644 --- a/docs/design/metrics.md +++ b/docs/design/metrics.md @@ -75,8 +75,14 @@ This list may be non-exhaustive. #### Component: Transaction Pool - `transaction_pool.inserted_transactions`: Number of transactions inserted in the pool -- `transaction_pool.invalid_transactions`: Number of invalid transactions +- `transaction_pool.invalid_transactions`: Number of invalid transactions - `transaction_pool.removed_transactions`: Number of removed transactions from the pool +- `transaction_pool.pending_pool_transactions`: Number of transactions in the pending sub-pool +- `transaction_pool.pending_pool_size_bytes`: Total amount of memory used by the transactions in the pending sub-pool in bytes +- `transaction_pool.basefee_pool_transactions`: Number of transactions in the basefee sub-pool +- `transaction_pool.basefee_pool_size_bytes`: Total amount of memory used by the transactions in the basefee sub-pool in bytes +- `transaction_pool.queued_pool_transactions`: Number of transactions in the queued sub-pool +- `transaction_pool.queued_pool_size_bytes`: Total amount of memory used by the transactions in the queued sub-pool in bytes #### Component: Network