Skip to content

Commit

Permalink
feat(txpool): add sub-pools length and size metrics (paradigmxyz#2598)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
leovct and mattsse authored May 9, 2023
1 parent 0798323 commit c0cbb6a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
17 changes: 16 additions & 1 deletion crates/transaction-pool/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Transaction pool metrics.
use metrics::Counter;
use metrics::{Counter, Gauge};
use reth_metrics_derive::Metrics;

/// Transaction pool metrics
Expand All @@ -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,
}
14 changes: 14 additions & 0 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,23 @@ impl<T: TransactionOrdering> TxPool<T> {
// 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`.
Expand Down
8 changes: 7 additions & 1 deletion docs/design/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c0cbb6a

Please sign in to comment.