Skip to content

Commit

Permalink
add eviction metrics to caches (#5523)
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a authored Oct 25, 2024
1 parent 312f5c3 commit 105aa7d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions quickwit/quickwit-storage/src/cache/byte_range_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ impl<T: 'static + ToOwned + ?Sized + Ord> NeedMutByteRangeCache<T> {
self.num_bytes -= num_bytes as u64;
self.cache_counters.in_cache_count.dec();
self.cache_counters.in_cache_num_bytes.sub(num_bytes as i64);
self.cache_counters.evict_num_items.inc();
self.cache_counters.evict_num_bytes.inc_by(num_bytes as u64);
}
}

Expand Down
3 changes: 3 additions & 0 deletions quickwit/quickwit-storage/src/cache/memory_sized_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct NeedMutMemorySizedCache<K: Hash + Eq> {

impl<K: Hash + Eq> Drop for NeedMutMemorySizedCache<K> {
fn drop(&mut self) {
// we don't count this toward evicted entries, as we are clearing the whole cache
self.cache_counters
.in_cache_count
.sub(self.num_items as i64);
Expand Down Expand Up @@ -110,6 +111,8 @@ impl<K: Hash + Eq> NeedMutMemorySizedCache<K> {
self.num_bytes -= num_bytes;
self.cache_counters.in_cache_count.dec();
self.cache_counters.in_cache_num_bytes.sub(num_bytes as i64);
self.cache_counters.evict_num_items.inc();
self.cache_counters.evict_num_bytes.inc_by(num_bytes);
}

pub fn get<Q>(&mut self, cache_key: &Q) -> Option<OwnedBytes>
Expand Down
3 changes: 3 additions & 0 deletions quickwit/quickwit-storage/src/file_descriptor_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ impl FileDescriptorCache {
self.fd_cache_metrics
.in_cache_count
.set(fd_cache_lock.len() as i64);
self.fd_cache_metrics
.evict_num_items
.inc_by(split_ids.len() as u64);
}

pub async fn get_or_open_split_file(
Expand Down
14 changes: 14 additions & 0 deletions quickwit/quickwit-storage/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub struct CacheMetrics {
pub hits_num_items: IntCounter,
pub hits_num_bytes: IntCounter,
pub misses_num_items: IntCounter,
pub evict_num_items: IntCounter,
pub evict_num_bytes: IntCounter,
}

impl CacheMetrics {
Expand Down Expand Up @@ -157,6 +159,18 @@ impl CacheMetrics {
CACHE_METRICS_NAMESPACE,
&[("component_name", component_name)],
),
evict_num_items: new_counter_with_labels(
"cache_evict_total",
"Number of cache entry evicted by component",
CACHE_METRICS_NAMESPACE,
&[("component_name", component_name)],
),
evict_num_bytes: new_counter_with_labels(
"cache_evict_bytes",
"Number of cache entry evicted in bytes by component",
CACHE_METRICS_NAMESPACE,
&[("component_name", component_name)],
),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions quickwit/quickwit-storage/src/split_cache/split_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ impl SplitTable {
.searcher_split_cache
.in_cache_num_bytes
.sub(num_bytes as i64);
crate::metrics::STORAGE_METRICS
.searcher_split_cache
.evict_num_items
.inc();
crate::metrics::STORAGE_METRICS
.searcher_split_cache
.evict_num_bytes
.inc_by(num_bytes);
&mut self.on_disk_splits
}
};
Expand Down

0 comments on commit 105aa7d

Please sign in to comment.