Skip to content

Conversation

@f41gh7
Copy link
Contributor

@f41gh7 f41gh7 commented Aug 6, 2025

It's incremented on bucket clean up and reports bytes
evicted from memory. It should help to understand an amount of extra memory needed for fastcache to serve requests rate on constantly evicted keys.

Related PR VictoriaMetrics/VictoriaMetrics#9293

 It's incremented on bucket clean up and reports bytes
evicted from memory. It should help to understand an amount of extra
memory needed for fastcache to serve requests rate on constantly evicted
keys.

Related PR VictoriaMetrics/VictoriaMetrics#9293
@f41gh7 f41gh7 requested review from Copilot, makasim and rtm0 August 6, 2025 08:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Introduces a new EvictedBytes metric to track the total amount of bytes evicted from the fastcache when bucket cleanup occurs. This metric helps understand memory pressure and determine how much additional memory would be needed to avoid evictions for a given request rate.

  • Added EvictedBytes field to the Stats struct to expose the metric
  • Added corresponding evictedBytes counter to the internal bucket struct
  • Integrated the counter into bucket operations (reset, stats collection, and eviction tracking)

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.81%. Comparing base (2693e48) to head (bf3a693).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   76.68%   76.81%   +0.12%     
==========================================
  Files           4        4              
  Lines         549      552       +3     
==========================================
+ Hits          421      424       +3     
  Misses         73       73              
  Partials       55       55              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@f41gh7 f41gh7 merged commit 1412165 into master Aug 6, 2025
7 checks passed
@f41gh7 f41gh7 deleted the evicted-bytes branch August 6, 2025 15:38
valyala added a commit that referenced this pull request Nov 10, 2025
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
@valyala
Copy link
Collaborator

valyala commented Nov 10, 2025

FYI, this pull request has been reverted in the commit f608073 . Reason for revert - the introduced EvictedBytes metric is misleading and it has zero practical sense.

valyala added a commit to VictoriaMetrics/VictoriaMetrics that referenced this pull request Nov 10, 2025
…1.13.2

This is needed for removing the EvictedBytes metric from the fastcache.

See the description of VictoriaMetrics/fastcache@f608073 for details.

Updates #9293
Updates VictoriaMetrics/fastcache#93
valyala added a commit to VictoriaMetrics/VictoriaMetrics that referenced this pull request Nov 10, 2025
…1.13.2

This is needed for removing the EvictedBytes metric from the fastcache.

See the description of VictoriaMetrics/fastcache@f608073 for details.

Updates #9293
Updates VictoriaMetrics/fastcache#93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants