Skip to content

Commit 105aa7d

Browse files
add eviction metrics to caches (#5523)
1 parent 312f5c3 commit 105aa7d

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

quickwit/quickwit-storage/src/cache/byte_range_cache.rs

+2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ impl<T: 'static + ToOwned + ?Sized + Ord> NeedMutByteRangeCache<T> {
314314
self.num_bytes -= num_bytes as u64;
315315
self.cache_counters.in_cache_count.dec();
316316
self.cache_counters.in_cache_num_bytes.sub(num_bytes as i64);
317+
self.cache_counters.evict_num_items.inc();
318+
self.cache_counters.evict_num_bytes.inc_by(num_bytes as u64);
317319
}
318320
}
319321

quickwit/quickwit-storage/src/cache/memory_sized_cache.rs

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct NeedMutMemorySizedCache<K: Hash + Eq> {
7474

7575
impl<K: Hash + Eq> Drop for NeedMutMemorySizedCache<K> {
7676
fn drop(&mut self) {
77+
// we don't count this toward evicted entries, as we are clearing the whole cache
7778
self.cache_counters
7879
.in_cache_count
7980
.sub(self.num_items as i64);
@@ -110,6 +111,8 @@ impl<K: Hash + Eq> NeedMutMemorySizedCache<K> {
110111
self.num_bytes -= num_bytes;
111112
self.cache_counters.in_cache_count.dec();
112113
self.cache_counters.in_cache_num_bytes.sub(num_bytes as i64);
114+
self.cache_counters.evict_num_items.inc();
115+
self.cache_counters.evict_num_bytes.inc_by(num_bytes);
113116
}
114117

115118
pub fn get<Q>(&mut self, cache_key: &Q) -> Option<OwnedBytes>

quickwit/quickwit-storage/src/file_descriptor_cache.rs

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ impl FileDescriptorCache {
119119
self.fd_cache_metrics
120120
.in_cache_count
121121
.set(fd_cache_lock.len() as i64);
122+
self.fd_cache_metrics
123+
.evict_num_items
124+
.inc_by(split_ids.len() as u64);
122125
}
123126

124127
pub async fn get_or_open_split_file(

quickwit/quickwit-storage/src/metrics.rs

+14
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub struct CacheMetrics {
120120
pub hits_num_items: IntCounter,
121121
pub hits_num_bytes: IntCounter,
122122
pub misses_num_items: IntCounter,
123+
pub evict_num_items: IntCounter,
124+
pub evict_num_bytes: IntCounter,
123125
}
124126

125127
impl CacheMetrics {
@@ -157,6 +159,18 @@ impl CacheMetrics {
157159
CACHE_METRICS_NAMESPACE,
158160
&[("component_name", component_name)],
159161
),
162+
evict_num_items: new_counter_with_labels(
163+
"cache_evict_total",
164+
"Number of cache entry evicted by component",
165+
CACHE_METRICS_NAMESPACE,
166+
&[("component_name", component_name)],
167+
),
168+
evict_num_bytes: new_counter_with_labels(
169+
"cache_evict_bytes",
170+
"Number of cache entry evicted in bytes by component",
171+
CACHE_METRICS_NAMESPACE,
172+
&[("component_name", component_name)],
173+
),
160174
}
161175
}
162176
}

quickwit/quickwit-storage/src/split_cache/split_table.rs

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ impl SplitTable {
165165
.searcher_split_cache
166166
.in_cache_num_bytes
167167
.sub(num_bytes as i64);
168+
crate::metrics::STORAGE_METRICS
169+
.searcher_split_cache
170+
.evict_num_items
171+
.inc();
172+
crate::metrics::STORAGE_METRICS
173+
.searcher_split_cache
174+
.evict_num_bytes
175+
.inc_by(num_bytes);
168176
&mut self.on_disk_splits
169177
}
170178
};

0 commit comments

Comments
 (0)