7

I have a Rails app which uses caching extensively and I want to know cache hit rate for different places in the app. Low hit rate places obviously need attention. But measure first!

To obtain real data I use graphite + statsd combo and a custom Dalli instrumentation employing statsd-instrument gem. All keys in the app are in form ['place', details...], so I get following metrics in graphite:

  • stats.cache.place1.hits
  • stats.cache.place1.misses
  • stats.cache.place2.hits
  • stats.cache.place2.misses
  • etc.

Now I want to show all hit rates. I was able to come up with following formula for one place:

divideSeries(stats.cache.place1.hits, sumSeries(stats.cache.place1.*))

It works quite well, but there are several dozen places and I'd hate to duplicate it, not to mention that new places can appear.

This is a question for you, Graphite experts: is there a way to show hit rates for all places? I've seen group* functions in the docs, but they confuse me.

Ideally I want to segment my places into 4 categories:

  • High hit rate, many requests. Caching is doing good job.
  • Low hit rate, many requests. Needs attention.
  • High hit rate, few requests. Is caching needed at all?
  • Low hit rate, few requests. Definitely remove caching.

I'd be really grateful for any ideas how to use graphite for such analysis (I can request data in JSON format and do my own math, but I suspect there must be a simpler way).

4

1 回答 1

3

您可以在多个级别使用 glob,因此对于所有缓存如何执行的全局视图:

divideSeries(stats.cache.*.hits, sumSeries(stats.cache.*.*))

对于您提到的 4 个类别,mostDeviant功能可能很好,这将有助于找到最高/最低的缓存率。

mostDeviant(5, divideSeries(stats.cache.*.hits, sumSeries(stats.cache.*.*)))

根据请求将它们分组到存储桶中,然后显示单独的派生比率更难。使用重复groupByNodehighestAverage可能工作的回调函数

highestAverage(groupByNode(groupByNode(stats.cache.*.*, 3, "sumSeries"), 2, "divideSeries"), 10)

附带说明一下,对于大多数 LRU(最近最少使用)缓存驱逐方案,删除缓存没有多大意义,因为它不会竞争缓存空间。

于 2014-07-27T14:27:49.597 回答