invalidateAll question #835
-
Hello, I have a synchronous cache with caffeine 1.3.1 running on a 8-core server. It's working perfectly. The point is when I try to invalidate all or parts of the cache. This cache can have millions of entries and the user can invalidate all entries or part of them. Performing an invalidateAll with a 4-millions entry cache locks the entire cache for 4 seconds, or at least this is what it seems, so during this time we don't see incoming traffic registered in our log. This is the log when the operation starts/ends: And this is the access log that traces all incoming requests, Below the first line registered after the invalidateAll finishes: As you can see the operation starts at 14:53:25.940 and ends at 14:53:29.214. If we add a removal listener (even if it does nothing), then things are getting worse. The same test now takes 16 seconds: 10.1.0.9,14:35:52.051,S,7,A,90,A,36,A,300,N,,receiver03:8082,g,14194,1601,676,50,,2022-12-09 14:36:08.331 But, in addition to this, we are seeing that all caches are locked, not only the one that receives the invalidateAll. All other caches are differents instances of caffeine caches, and all the incoming traffic also disappears during the invalidateAll operation. I'm afraid we are misunderstanding something and thus doing something really wrong to get all caches locked. So we have two questions:
Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
While unfortunately this won't solve your problem, please consider upgrading to a recent release (v2 for Java 8, else v3).
The removal listener call is delegated to the configured executor, so within the invalidation it should be immediate. You might be suffering if you configured to a direct executor (e.g. The cache should still accept read/write operations and only locked wrt the eviction policy. Those operations schedule work against the policy through ring buffers, so that batches of events can be replayed under the lock without blocking. In the case of clearing the whole cache, acquiring this lock is generally cheaper than iterating over the map to queue a delete task per entry. A possible problem might be if you use long computations, as these are performed by
At 4M entries this usually isn't a problem as there should be a good distribution within the table. However if it is, you might consider using
The cache itself should not have any cross-instance state that could cause slow downs. If you have callbacks that use shared locks, e.g. in your |
Beta Was this translation helpful? Give feedback.
While unfortunately this won't solve your problem, please consider upgrading to a recent release (v2 for Java 8, else v3).
The removal listener call is delegated to the configured executor, so within the invalidation it should be immediate. You might be suffering if you configured to a direct executor (e.g.
Runnable::run
) or thread scheduling is causing the invalidation to be deprioritized.The cache should still accept read/write operations and only locked wrt the eviction po…