arturobernalg opened a new pull request, #1275:
URL: https://github.com/apache/tomcat/pull/1275

   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 in 
`Cache.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.
   
   | Scenario | Build | Requests/s | p50 | p99 | p99.9 |
   |---|---|---|---|---|---|
   | 32,000 files, cache full | original | 5,566 - 5,878 | 4.5 ms | 22 ms | 35 
ms |
   | 32,000 files, cache full | patched | 32,244 - 33,738 | 0.98 ms | 3.1 ms | 
6.7 ms |
   | 4,000 files, fits in cache | original | 205,309 - 210,125 | 0.13 ms | 0.51 
ms | 1.3 ms |
   | 4,000 files, fits in cache | patched | 207,489 - 213,393 | 0.13 ms | 0.50 
ms | 1.3 ms |
   | 32,000 files, 1 GB cache | original | 122,610 | 0.19 ms | 1.2 ms | 2.7 ms |
   | 32,000 files, 1 GB cache | patched | 126,111 | 0.19 ms | 1.2 ms | 2.6 ms |
   
   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 `TestCache` cover 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to