Repository navigation
Avoid a full resource cache scan on every miss when nothing can be ev… - #1275
Open
arturobernalg wants to merge 1 commit into
Open
arturobernalg wants to merge 1 commit into
arturobernalg wants to merge 1 commit into
Conversation
…icted When the static resource cache is full and every entry was validated within the TTL, each cache miss scanned the whole cache without being able to evict anything. Remember when the first entry expires and skip the scan until then.
arturobernalg
force-pushed
the
resource-cache-evict-scan
branch
from
November 27, 2026 13:12
6be0efe to
7337c52
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the static resource cache is full and every entry was validated within the TTL, each cache miss iterates the whole cache in
evict()without being able to remove anything, then drops the new entry. Under load every miss becomes a full scan; a JFR profile of the server showed 97% of CPU inCache.evict().This change remembers the earliest time a skipped entry can expire and skips the scan until then, so there is at most one scan per expiry instant instead of one per miss. The eviction policy is unchanged.
I measured it on a real Tomcat built from main, with the default cache configuration. The client was a keep-alive load generator with 32 connections, with server and client pinned to separate cores. Each run had 10 s of warm-up and 30 s of measurement, Tomcat was restarted before every run, and original and patched runs alternated.
With a full cache, throughput improves about 5.8x and p99 latency drops about 7x. When the working set fits in the cache, or the cache never fills, the results are unchanged. The remaining gap to the large cache case is the per-miss warning and reading uncached files, which this change does not touch.
The new tests in
TestCachecover a full cache, eviction resuming after entries expire, staggered expiry and the directory listing path. BZ 66564 proposes a broader redesign of eviction order; this change is independent of it.