Skip to main content

CacheMetrics

Struct CacheMetrics 

Source
pub struct CacheMetrics {
    pub hits: AtomicU64,
    pub misses: AtomicU64,
    pub evictions: AtomicU64,
    pub admissions: AtomicU64,
    pub contention_events: AtomicU64,
}

Fields§

§hits: AtomicU64§misses: AtomicU64§evictions: AtomicU64§admissions: AtomicU64§contention_events: AtomicU64

Implementations§

Source§

impl CacheMetrics

Source

pub fn new() -> Self

Source

pub fn hits(&self) -> u64

Examples found in repository?
examples/sample_app.rs (line 230)
216fn metrics_hit_ratio() {
217    use subms_block_cache::MetricsCache;
218    println!("\n== metrics: hit-ratio observability ==");
219    let mut cache: MetricsCache<u64, String> = MetricsCache::with_capacity(4);
220    for id in 0u64..4 {
221        cache.put(id, read_block(id));
222    }
223    let _ = cache.get(&0);
224    let _ = cache.get(&1);
225    let _ = cache.get(&2);
226    let _ = cache.get(&99);
227    let m = cache.metrics();
228    println!(
229        "  hits {}, misses {}, hit ratio {:.2}",
230        m.hits(),
231        m.misses(),
232        m.hit_ratio()
233    );
234    assert_eq!(m.hits(), 3);
235    assert_eq!(m.misses(), 1);
236    assert!((m.hit_ratio() - 0.75).abs() < 1e-9);
237}
Source

pub fn misses(&self) -> u64

Examples found in repository?
examples/sample_app.rs (line 231)
216fn metrics_hit_ratio() {
217    use subms_block_cache::MetricsCache;
218    println!("\n== metrics: hit-ratio observability ==");
219    let mut cache: MetricsCache<u64, String> = MetricsCache::with_capacity(4);
220    for id in 0u64..4 {
221        cache.put(id, read_block(id));
222    }
223    let _ = cache.get(&0);
224    let _ = cache.get(&1);
225    let _ = cache.get(&2);
226    let _ = cache.get(&99);
227    let m = cache.metrics();
228    println!(
229        "  hits {}, misses {}, hit ratio {:.2}",
230        m.hits(),
231        m.misses(),
232        m.hit_ratio()
233    );
234    assert_eq!(m.hits(), 3);
235    assert_eq!(m.misses(), 1);
236    assert!((m.hit_ratio() - 0.75).abs() < 1e-9);
237}
Source

pub fn evictions(&self) -> u64

Source

pub fn admissions(&self) -> u64

Source

pub fn contention_events(&self) -> u64

Source

pub fn hit_ratio(&self) -> f64

Examples found in repository?
examples/sample_app.rs (line 232)
216fn metrics_hit_ratio() {
217    use subms_block_cache::MetricsCache;
218    println!("\n== metrics: hit-ratio observability ==");
219    let mut cache: MetricsCache<u64, String> = MetricsCache::with_capacity(4);
220    for id in 0u64..4 {
221        cache.put(id, read_block(id));
222    }
223    let _ = cache.get(&0);
224    let _ = cache.get(&1);
225    let _ = cache.get(&2);
226    let _ = cache.get(&99);
227    let m = cache.metrics();
228    println!(
229        "  hits {}, misses {}, hit ratio {:.2}",
230        m.hits(),
231        m.misses(),
232        m.hit_ratio()
233    );
234    assert_eq!(m.hits(), 3);
235    assert_eq!(m.misses(), 1);
236    assert!((m.hit_ratio() - 0.75).abs() < 1e-9);
237}
Source

pub fn record_hit(&self)

Source

pub fn record_miss(&self)

Source

pub fn record_eviction(&self)

Source

pub fn record_admission(&self)

Source

pub fn record_contention(&self)

Trait Implementations§

Source§

impl Debug for CacheMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheMetrics

Source§

fn default() -> CacheMetrics

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.