Skip to content

Commit f608073

Browse files
committed
Revert "introduce new stats item EvictedBytes (#93)"
This reverts commit 1412165. Reason for revert: the exposed EvictedBytes metric is misleading - it doesn't reflect the real eviction rate of the data in the cache, since old data is overwritten by the new data in the cyclic buffer formed from the cache chunks, on the addition of new items to the cache. It is impossible to detect the eviction rate since the code doesn't know when it overwrites the already existing data. The EvictedBytes metric is just increased by the total size of chunks on every wraparound in the shard. This can be used as a rough estimation of the evicted bytes, but it is updated too rarely on large caches. It is possible to add WrittenBytes metric, which will show the number of bytes written to the cache. This metric roughly equals to the EvictedBytes metric after the cache becomes full and old data starts to be overwritten by the new data. Both metrics have zero practical applicability, so it is better to drop the EvictedBytes metric even if it has been already exposed in public, in order to reduce the complexity of the code and reduce the confusion for the users who try using this metric. All the users of this metric must stop using it. Updates #93 Updates VictoriaMetrics/VictoriaMetrics#9293
1 parent 9bc5415 commit f608073

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

fastcache.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ type Stats struct {
5656
// MaxBytesSize is the maximum allowed size of the cache in bytes (aka capacity).
5757
MaxBytesSize uint64
5858

59-
// EvictedBytes is the amount of bytes evicted from cache
60-
EvictedBytes uint64
61-
6259
// BigStats contains stats for GetBig/SetBig methods.
6360
BigStats
6461
}
@@ -237,9 +234,8 @@ type bucket struct {
237234
// idx points to chunks for writing the next (k, v) pair.
238235
idx uint64
239236

240-
collisions uint64
241-
corruptions uint64
242-
evictedBytes uint64
237+
collisions uint64
238+
corruptions uint64
243239
}
244240

245241
func (b *bucket) Init(maxBytes uint64) {
@@ -270,7 +266,6 @@ func (b *bucket) Reset() {
270266
atomic.StoreUint64(&b.misses, 0)
271267
atomic.StoreUint64(&b.collisions, 0)
272268
atomic.StoreUint64(&b.corruptions, 0)
273-
atomic.StoreUint64(&b.evictedBytes, 0)
274269
b.mu.Unlock()
275270
}
276271

@@ -308,7 +303,6 @@ func (b *bucket) UpdateStats(s *Stats) {
308303
s.Misses += atomic.LoadUint64(&b.misses)
309304
s.Collisions += atomic.LoadUint64(&b.collisions)
310305
s.Corruptions += atomic.LoadUint64(&b.corruptions)
311-
s.EvictedBytes += atomic.LoadUint64(&b.evictedBytes)
312306

313307
b.mu.RLock()
314308
s.EntriesCount += uint64(len(b.m))
@@ -377,7 +371,6 @@ func (b *bucket) Set(k, v []byte, h uint64) {
377371
b.idx = idxNew
378372
if needClean {
379373
b.cleanLocked()
380-
atomic.AddUint64(&b.evictedBytes, uint64(len(chunks)*chunkSize))
381374
}
382375
b.mu.Unlock()
383376
}

0 commit comments

Comments
 (0)