mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): track cache hits and misses (#5094)
This commit is contained in:
5
crates/rpc/rpc/src/eth/cache/metrics.rs
vendored
5
crates/rpc/rpc/src/eth/cache/metrics.rs
vendored
@ -1,3 +1,4 @@
|
||||
use metrics::Counter;
|
||||
use reth_metrics::{metrics::Gauge, Metrics};
|
||||
|
||||
#[derive(Metrics)]
|
||||
@ -7,4 +8,8 @@ pub(crate) struct CacheMetrics {
|
||||
pub(crate) cached_count: Gauge,
|
||||
/// The number of queued consumers.
|
||||
pub(crate) queued_consumers_count: Gauge,
|
||||
/// The number of cache hits.
|
||||
pub(crate) hits: Counter,
|
||||
/// The number of cache misses.
|
||||
pub(crate) misses: Counter,
|
||||
}
|
||||
|
||||
@ -70,7 +70,13 @@ where
|
||||
/// Returns a reference to the value for a given key and promotes that element to be the most
|
||||
/// recently used.
|
||||
pub fn get(&mut self, key: &K) -> Option<&mut V> {
|
||||
self.cache.get(key)
|
||||
let entry = self.cache.get(key);
|
||||
if entry.is_some() {
|
||||
self.metrics.hits.increment(1);
|
||||
} else {
|
||||
self.metrics.misses.increment(1);
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
||||
/// Inserts a new element into the map.
|
||||
|
||||
Reference in New Issue
Block a user