mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 07:17:56 -05:00
add truncate metrics
This commit is contained in:
@@ -972,6 +972,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// The original capacity reservation may have been too large, so we shrink the vector to
|
||||
// the actual number of transactions to import.
|
||||
// new_txs.shrink_to_fit();
|
||||
|
||||
// import new transactions as a batch to minimize lock contention on the underlying pool
|
||||
if !new_txs.is_empty() {
|
||||
let pool = self.pool.clone();
|
||||
|
||||
@@ -41,6 +41,18 @@ pub struct TxPoolMetrics {
|
||||
|
||||
/// How often the pool was updated after the canonical state changed
|
||||
pub(crate) performed_state_updates: Counter,
|
||||
|
||||
/// Total `discard_worst` calls
|
||||
pub(crate) discard_worst_calls: Counter,
|
||||
|
||||
/// How long it took the pool to `discard_worst`
|
||||
pub(crate) discard_worst_duration: Gauge,
|
||||
|
||||
/// How many times `discard_worst` looped
|
||||
pub(crate) discard_worst_loops: Gauge,
|
||||
|
||||
/// How many transactions were removed in the last `discard_worst` call
|
||||
pub(crate) discard_worst_removed: Gauge,
|
||||
}
|
||||
|
||||
/// Transaction pool blobstore metrics
|
||||
|
||||
@@ -756,6 +756,10 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
/// This returns all transactions that were removed from the entire pool.
|
||||
pub(crate) fn discard_worst(&mut self) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
let mut removed = Vec::new();
|
||||
self.metrics.discard_worst_calls.increment(1);
|
||||
|
||||
let now = std::time::Instant::now();
|
||||
let mut loops = 0;
|
||||
|
||||
// Helper macro that discards the worst transactions for the pools
|
||||
macro_rules! discard_worst {
|
||||
@@ -766,6 +770,7 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
.$limit
|
||||
.is_exceeded($this.$pool.len(), $this.$pool.size())
|
||||
{
|
||||
loops += 1;
|
||||
trace!(
|
||||
"discarding transactions from {}, limit: {:?}, curr size: {}, curr len: {}",
|
||||
stringify!($pool),
|
||||
@@ -813,6 +818,11 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
]
|
||||
);
|
||||
|
||||
let elapsed = now.elapsed();
|
||||
self.metrics.discard_worst_duration.set(elapsed.as_secs_f64());
|
||||
self.metrics.discard_worst_removed.set(removed.len() as f64);
|
||||
self.metrics.discard_worst_loops.set(loops as f64);
|
||||
|
||||
removed
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user