Dynamically toggling recording stats on Caffeine Cache

陌路散爱 提交于 2021-02-11 13:52:43

问题


I would like to be able to dynamically toggle the recording of stats of Caffeine Caches on demand via REST endpoint, or JMX Method

We have a large scale application where we use several instances of Caffeine Caches. We could use every possible performance upgrade, so having it in constant recording seems redundant. Especially if JavaDoc says recording has a performance cost. After my analysis I think it is not directly supported. Or is it?

I have 2 goals for stats, 1st one is to be able to tweak our caching strategy. To identify where we have terrible hit-rate, or where we actually don't need the cache. To accommodate this we could possibly do a temporary release with recording turned on and then do the final release. Meaning this solution would not be dynamic at all.

The 2nd goal would be to use it to identify cause of system failures. To diagnose erroneous state on a live production environment. To keep all my ideal requirements this would have to be dynamic. If I cannot change cache instance, I thought I could possibly replace the instance. This would bring huge temporal load on the system, since it would basically purge all caches.

To avoid purging we could maybe somehow pass on values cheaply to new instance with stats recording toggled. I don't yet know how, or if even possible.

So my question is what is the best way of achieving my goals?


回答1:


You are correct, there is no support for configuring stats dynamically. However you can supply your own StatsCounter that could offer this support.

The cost of using the built-in StatsCounter should be cheap due to storing into LongAdder counters. On an unclean environment, I observed a decrease in read throughput by 20% but still over 100M ops/s. At that throughput the cache should not be the bottleneck given real application logic.

Most likely you can turn statistics on without worry. If you are concerned then try benchmarking first to see if the additional workarounds are worth the effort. If so, likely a custom StatsCounter is acceptable (but again, benchmark).



来源:https://stackoverflow.com/questions/59566399/dynamically-toggling-recording-stats-on-caffeine-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!