Skip to content

cache maintains size greater than the defined maximumSize for a long time (1h+) #420

@jakubzytka

Description

@jakubzytka

I'm observing a weird behavior of caffeine cache v2.4.0. This issue presumably goes away when caffeine is upgraded to v2.8.1.

I'm seeking a confirmation whether this is an old, fixed issue (possibly by e8ff6d3) or if that's a new issue and I was just lucky to not see it after the upgrade.
I'd greatly appreciate any comments.

The issue:
I have a cache with a removalListener and a maximumSize, say 32767.
I'm observing that the cache size (measured by the number of put minus the number of removalListener calls) sometimes gets stuck at 32768. There is a constant getIfPresent load, but no put happens when the cache size stays at 32768.
Sometimes this condition gets magically resolved but it usually takes hours.
The moment of resolution is often correlated with a reduction in the number of cache accesses (as if some cleanup task was being starved? On the other hand I do see parked ForkJoinPool threads)

This is a problem because a certain component (specifically, Solr's BlockCache) relies on cache size getting down to maximumSize in a reasonably short time. Is such an expectation reasonable?
Side note: I ensured immutability of cache key (BlockCacheKey in case of Solr) so no hanky-panky with hashCode/equals is involved.

I gathered stack traces during the period when the cache is "stuck". They show that some sort of cleanup is triggered:

   java.lang.Thread.State: RUNNABLE
        at sun.misc.Unsafe.unpark(Native Method)
        at java.util.concurrent.ForkJoinPool.signalWork(ForkJoinPool.java:1649)
        at java.util.concurrent.ForkJoinPool.externalPush(ForkJoinPool.java:2414)
        at java.util.concurrent.ForkJoinPool.execute(ForkJoinPool.java:2648)
        at com.datastax.bdp.shade.com.github.benmanes.caffeine.cache.BoundedLocalCache.scheduleDrainBuffers(BoundedLocalCache.java:976)
        at com.datastax.bdp.shade.com.github.benmanes.caffeine.cache.BoundedLocalCache.afterRead(BoundedLocalCache.java:815)
        at com.datastax.bdp.shade.com.github.benmanes.caffeine.cache.BoundedLocalCache.getIfPresent(BoundedLocalCache.java:1443)
        at com.datastax.bdp.shade.com.github.benmanes.caffeine.cache.LocalManualCache.getIfPresent(LocalManualCache.java:49)
...
   Locked ownable synchronizers:
        - <0x0000000410f48a70> (a java.util.concurrent.ThreadPoolExecutor$Worker)
        - <0x000000047fab2498> (a com.github.benmanes.caffeine.cache.NonReentrantLock$Sync)

I also can see that there are unutilized ForkJoinPool threads afterward, e.g.:

   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x0000000410f2ac48> (a java.util.concurrent.ForkJoinPool)
        at java.util.concurrent.ForkJoinPool.awaitWork(ForkJoinPool.java:1824)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1693)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions