Skip to content

Commit

Permalink
Add e-tps to logged mempool metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
tiram88 committed Sep 21, 2023
1 parent 14da8a2 commit db0cddf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 9 additions & 3 deletions mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct MiningCounters {
pub tx_accepted_counts: AtomicU64,
pub input_counts: AtomicU64,
pub output_counts: AtomicU64,
pub mempool_sample: AtomicU64,
}

impl MiningCounters {
Expand All @@ -33,6 +34,7 @@ impl MiningCounters {
tx_accepted_counts: self.tx_accepted_counts.load(Ordering::Relaxed),
input_counts: self.input_counts.load(Ordering::Relaxed),
output_counts: self.output_counts.load(Ordering::Relaxed),
mempool_sample: self.mempool_sample.load(Ordering::Relaxed),
}
}

Expand All @@ -56,16 +58,19 @@ pub struct MempoolCountersSnapshot {
pub tx_accepted_counts: u64,
pub input_counts: u64,
pub output_counts: u64,
pub mempool_sample: u64,
}

impl MempoolCountersSnapshot {
pub fn in_tx_counts(&self) -> u64 {
self.high_priority_tx_counts + self.low_priority_tx_counts
}

pub fn collision_ratio(&self) -> f64 {
if self.block_tx_counts > 0 {
(self.block_tx_counts - self.tx_accepted_counts) as f64 / self.block_tx_counts as f64
pub fn e_tps(&self) -> f64 {
let accepted_txs = u64::min(self.mempool_sample, self.tx_accepted_counts);
let total_txs = u64::min(self.mempool_sample, self.block_tx_counts);
if total_txs > 0 {
accepted_txs as f64 / total_txs as f64
} else {
0f64
}
Expand All @@ -83,6 +88,7 @@ impl core::ops::Sub for &MempoolCountersSnapshot {
tx_accepted_counts: self.tx_accepted_counts.checked_sub(rhs.tx_accepted_counts).unwrap_or_default(),
input_counts: self.input_counts.checked_sub(rhs.input_counts).unwrap_or_default(),
output_counts: self.output_counts.checked_sub(rhs.output_counts).unwrap_or_default(),
mempool_sample: (self.mempool_sample + rhs.mempool_sample) / 2,
}
}
}
5 changes: 4 additions & 1 deletion mining/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use kaspa_consensusmanager::{spawn_blocking, ConsensusProxy};
use kaspa_core::{debug, error, info, time::Stopwatch, warn};
use kaspa_mining_errors::mempool::RuleError;
use parking_lot::RwLock;
use std::sync::Arc;
use std::sync::{atomic::Ordering, Arc};
use tokio::sync::mpsc::UnboundedSender;

pub struct MiningManager {
Expand Down Expand Up @@ -509,6 +509,9 @@ impl MiningManager {
// alternate no & write lock on mempool
let accepted_transactions = self.validate_and_insert_unorphaned_transactions(consensus, unorphaned_transactions);

// read lock on mempool
self.counters.mempool_sample.store(self.mempool.read().transaction_count(true, false) as u64, Ordering::SeqCst);

// write lock on mempool
self.mempool.write().log_stats();

Expand Down
4 changes: 2 additions & 2 deletions mining/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl MiningMonitor {
let now = Instant::now();
let elapsed = (now - last_log_time).as_secs_f64();

info!("Processed {} unique transactions in the last {:.2}s ({:.2} avg txs/s, in: {} via RPC, {} via P2P, out: {} via accepted blocks, {:.2}% collisions)",
info!("Processed {} unique transactions in the last {:.2}s ({:.2} avg txs/s, in: {} via RPC, {} via P2P, out: {} via accepted blocks, {:.2}% e-tps)",
delta.tx_accepted_counts,
elapsed,
delta.tx_accepted_counts as f64 / elapsed,
delta.high_priority_tx_counts,
delta.low_priority_tx_counts,
delta.block_tx_counts,
delta.collision_ratio() * 100.0,
delta.e_tps() * 100.0,
);

last_snapshot = snapshot;
Expand Down

0 comments on commit db0cddf

Please sign in to comment.