Reputation: 10639
I would like to use Infinispan as cache for image binary data (Java type byte[]
). I assume that Infinispan default strategy is LIFO or similar strategy that prefers to keep most recently used/added cache entity.
In my loadtest scenario I make four calls in the round to retrieve the given entity. It is assumed that first call never hits the cache (because each round a unique entity is requested), but following three always hit the cache. So the expected profile looks like this:
#1: MISS-HIT-HIT-HIT
#2: MISS-HIT-HIT-HIT
...
It works perfectly when I configure Infinispan with COUNT
eviction type with some number of entities:
<local-cache name="imagesCache" statistics="true">
<!-- lifespan="30 min" max-idle="30 min" interval="1 min" -->
<expiration lifespan="1800000" max-idle="1800000" interval="60000" />
<memory>
<binary eviction="COUNT" size="500" />
</memory>
</local-cache>
The stats shows exact 3/4 cache hit at the end of the run (as well as in the middle):
Cache hit ratio based on numbers I capture in loadtest: (2952-738)/2952 = 0.75
When I change the number of entities to keep in the memory (<binary eviction="COUNT" size="100" />
), hit ratio does not change (as expected).
During the run I have measured heap size before and after load test (measurements taken after several GC invocations) and it turns out that 500 entities take about 114.895.000 - 62.445.000 = 52.450.000
bytes = roughly 100KB per entity:
After that I have restarted the application with only this small change in cache configuration:
<memory>
<binary eviction="MEMORY" size="1000000" />
</memory>
I would expect that Infinispan performance has the same profile, however it turns out that once the given amount of memory is fully allocated, newly added entities don't evict old entities but get immediately evicted. It means that roughly after 100 entities are added, all four requests to cache result cache miss. One can see that ratio is now 0.58 instead of 0.75:
Cache hit ratio: (2952-738-504)/2952 = 0.579
If I increase the memory, indeed hit ratio comes closer to 0.75 however I would like hit ratio to be the same irrespective the memory size (provided that memory can fit at least few entities).
Once I configure the passivation to file, memory-based eviction policy starts to work as expected:
<local-cache name="imagesCache" statistics="true">
<expiration lifespan="1800000" max-idle="1800000" interval="60000" />
<persistence passivation="true">
<file-store path="/var/cache/infinispan" purge="true">
<write-behind thread-pool-size="5" />
</file-store>
</persistence>
<memory>
<binary eviction="MEMORY" size="1000000" />
</memory>
</local-cache>
Passivation → Attributes shows that number of passivations is 1121 (equal to number of evictions) and Activation → Attributes shows that number of activations is 1242. It means that some entities have been activated several times (and immediately evicted, which is not good). In general I expect that number of activations is zero.
Any idea how to configure memory-based eviction policy so that cache hit ratio is the same as for count-based policy?
Topics I've read in relation to above (they don't have a direct answer to above question):
Upvotes: 5
Views: 943