Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(txpool): add sub-pools length and size metrics #2598

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 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,23 @@ pub struct TxPoolMetrics {
pub(crate) invalid_transactions: Counter,
/// Number of removed transactions from the pool
pub(crate) removed_transactions: Counter,
/// Total number of transactions in the pool
pub(crate) total_number_transactions: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved
/// Total amount of memory used by the transactions in the pool in bytes
pub(crate) total_size_bytes: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved

/// Number of transactions in the pending sub-pool
pub(crate) pending_pool_length: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved
/// Total amount of memory used by the transactions in the pending sub-pool in bytes
pub(crate) pending_sub_pool_size_bytes: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved

/// Number of transactions in the basefee sub-pool
pub(crate) basefee_pool_length: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved
/// Total amount of memory used by the transactions in the basefee sub-pool in bytes
pub(crate) basefee_sub_pool_size_bytes: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved

/// Number of transactions in the queued sub-pool
pub(crate) queued_pool_length: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved
/// Total amount of memory used by the transactions in the queued sub-pool in bytes
pub(crate) queued_sub_pool_size_bytes: Gauge,
leovct marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 15 additions & 0 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl<T: TransactionOrdering> TxPool<T> {
/// Returns stats about the size of pool.
pub(crate) fn size(&self) -> PoolSize {
PoolSize {
total_transactions: self.len(),
total_size: self.pending_pool.size() +
self.basefee_pool.size() +
self.queued_pool.size(),
pending: self.pending_pool.len(),
pending_size: self.pending_pool.size(),
basefee: self.basefee_pool.len(),
Expand Down Expand Up @@ -253,6 +257,17 @@ impl<T: TransactionOrdering> TxPool<T> {
// Process the sub-pool updates
let UpdateOutcome { promoted, discarded } = self.process_updates(updates);

// Compute pool metrics
let stats = self.size();
self.metrics.total_number_transactions.set(stats.total_transactions as f64);
self.metrics.total_size_bytes.set(stats.total_size as f64);
self.metrics.pending_pool_length.set(stats.pending as f64);
self.metrics.pending_sub_pool_size_bytes.set(stats.pending_size as f64);
self.metrics.basefee_pool_length.set(stats.basefee as f64);
self.metrics.basefee_sub_pool_size_bytes.set(stats.basefee_size as f64);
self.metrics.queued_pool_length.set(stats.queued as f64);
self.metrics.queued_sub_pool_size_bytes.set(stats.queued_size as f64);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is ok cc @mattsse

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems ok!
looks correct


OnNewCanonicalStateOutcome { block_hash, mined: mined_transactions, promoted, discarded }
}

Expand Down
4 changes: 4 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ impl IntoRecoveredTransaction for PooledTransaction {
/// Represents the current status of the pool.
#[derive(Debug, Clone)]
pub struct PoolSize {
/// Number of transactions in the pool.
pub total_transactions: usize,
/// Reported size of transactions in the pool.
pub total_size: usize,
/// Number of transactions in the _pending_ sub-pool.
pub pending: usize,
/// Reported size of transactions in the _pending_ sub-pool.
Expand Down
8 changes: 8 additions & 0 deletions docs/design/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ This list may be non-exhaustive.
- `transaction_pool.inserted_transactions`: Number of transactions inserted in the pool
- `transaction_pool.invalid_transactions`: Number of invalid transactions
- `transaction_pool.removed_transactions`: Number of removed transactions from the pool
- `transaction_pool.total_number_transactions`: Total number of transactions in the pool
- `transaction_pool.total_size_bytes`: Total amount of memory used by the transactions in the pool in bytes
- `transaction_pool.pending_sub_pool_length`: Number of transactions in the pending sub-pool
- `transaction_pool.pending_sub_pool_size_bytes`: Total amount of memory used by the transactions in the pending sub-pool in bytes
- `transaction_pool.basefee_sub_pool_length`: Number of transactions in the basefee sub-pool
- `transaction_pool.basefee_sub_pool_size_bytes`: Total amount of memory used by the transactions in the basefee sub-pool in bytes
- `transaction_pool.queued_sub_pool_length`: Number of transactions in the queued sub-pool
- `transaction_pool.queued_sub_pool_size_bytes`: Total amount of memory used by the transactions in the queued sub-pool in bytes

#### Component: Network

Expand Down