-
Hi, I am using caffeine cache for one of my usecase. The moment I added my first entry into caffeineCacheInstance the size is increasing upto to 10000% Sample code
I am getting following response
Is this expected growth or am i doing something wrong. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I am unsure how your cache is configured, but the cache is allowed to exceed the maximum size by a modest amount to allow for improved concurrency. Internally the cache uses a write buffer to enque pending operations that need to be replayed against the eviction policy. This avoids having all writing threads block and run sequentially, which would be the common case once the cache is full. Instead, after the map operation the policy work is handed off and scheduled to be processed immediately. A typical cache would synchronize all writes and cause lock contention, even though the work to maintain LRU is inexpensive. In this model a batch of work can be applied and writes to distinct keys can be fully concurrent. The write buffer is bounded so if the write rate greatly exceeds the eviction rate then back pressure is applied where writers block to assist in the eviction, thereby avoiding runaway growth. You can run the eviction on the caller, e.g. We allow for 128 * NCPUs pending write ops, so this overflow is more visible on small caches in a tight insertion loop. It's more common to perform per-key loads though the cache, so with a good hit rate the writes are much less common than reads, meaning usually won't see it in practice. The cache favors minimizing the user-facing latencies before applying a strict threshold, so the maximum is a watermark but it will throttle once the tolerance limit was reached. |
Beta Was this translation helpful? Give feedback.
I am unsure how your cache is configured, but the cache is allowed to exceed the maximum size by a modest amount to allow for improved concurrency.
Internally the cache uses a write buffer to enque pending operations that need to be replayed against the eviction policy. This avoids having all writing threads block and run sequentially, which would be the common case once the cache is full. Instead, after the map operation the policy work is handed off and scheduled to be processed immediately. A typical cache would synchronize all writes and cause lock contention, even though the work to maintain LRU is inexpensive. In this model a batch of work can be applied and writes to distinct keys …