Skip to content

fix(cache): add exponential backoff for failed cache flush attempts#588

Merged
wskozlowski merged 5 commits into
mainfrom
feature/issue_539
Dec 7, 2025
Merged

fix(cache): add exponential backoff for failed cache flush attempts#588
wskozlowski merged 5 commits into
mainfrom
feature/issue_539

Conversation

@adrian-zawadzki

Copy link
Copy Markdown
Collaborator

Implement rate limiting for cache recycler flush operations to prevent performance degradation when cache limits are reached and memory cannot be freed.

When flush attempts fail to release sufficient memory (less than 10% of target flush size), the system now applies exponential backoff starting at 1 microsecond and doubling up to a maximum of 1 second between retry attempts. This prevents the cache recycler from hammering the system with continuous flush attempts that cannot succeed.

Key changes:

  • Add m_next_flush_time timestamp to track next allowed flush moment
  • Add m_current_flush_delay for exponential backoff tracking
  • Flush attempts only execute if current time >= m_next_flush_time
  • Success threshold: flushed size > 10% of target flush size
  • On success: reset delay to zero for immediate future flushes
  • On failure: double delay (1μs → 2μs → 4μs → ... → 1s max)

Fixes #539

Implement rate limiting for cache recycler flush operations to prevent
performance degradation when cache limits are reached and memory cannot
be freed.

When flush attempts fail to release sufficient memory (less than 10% of
target flush size), the system now applies exponential backoff starting
at 1 microsecond and doubling up to a maximum of 1 second between retry
attempts. This prevents the cache recycler from hammering the system
with continuous flush attempts that cannot succeed.

Key changes:
- Add m_next_flush_time timestamp to track next allowed flush moment
- Add m_current_flush_delay for exponential backoff tracking
- Flush attempts only execute if current time >= m_next_flush_time
- Success threshold: flushed size > 10% of target flush size
- On success: reset delay to zero for immediate future flushes
- On failure: double delay (1μs → 2μs → 4μs → ... → 1s max)

Fixes #539
updateSize(lock, m_capacity - flush_size);
flushed = true;
flush_result = m_current_size[priority] <= (m_capacity - flush_size);
auto now = std::chrono::high_resolution_clock::now();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we move this to a separate function ? this one is getting big and overly complex

…thod

Extracted cache eviction and backoff logic from CacheRecycler::update() into
a new private _flush() helper method to improve code maintainability and
reduce method complexity.
@wskozlowski wskozlowski merged commit 6033bad into main Dec 7, 2025
7 of 9 checks passed
@wskozlowski wskozlowski deleted the feature/issue_539 branch December 7, 2025 16:14
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.

Implement exponential-backoff policy for CacheRecycler flushing

2 participants