2
votes

Using Ehcache , after Java app works 2.5 days, I have this statistic

cacheHits:  31185262, approximate 131 per sec
cacheMisses:    4642979, approximate 19  per sec
evictedCount:   4106931, approximate 17 per sec

and last hour it looks like

cacheHits:  60 per sec
cacheMisses:    57 per sec
evictedCount:   53 per sec

size of cache=400000, items never expire.

Why does it happen?

2
from what you've posted, how can you tell that the entries being evicted are "recently used"? Are you sure that your application isn't just accessing a wide variety of items in your cache, both recently used and not-recently-used? - matt b
I am actually seeing a very very similar pattern on some production instances: after a week of running, some objects (that are expected to be cached) suddenly become persistent misses and always require going all the way to the DB. - mindas

2 Answers

4
votes

i guess i found the cause.

some time ago i upgraded ehcache from 1.6.xx to 1.7.xx. i didn't noticed that they changed implementation of evicting algorithm. now it works as follows: select random 15 keys(!, they use some heuristics, but nevertheless it is still random), then find corresponding elements, select last recently used element from selected ones. (you can figure out it by yourself after looking a MemoryStore class). after that not surprising that it works very very bad.

good news is that you can use old implementation by setting a property "net.sf.ehcache.use.classic.lru"=true. after i did that my problem disappeared