Why ever use CachedGauage in Dropwizard Metrics?
Asked Answered
M

2

5

I see there is the CachedGauge in the DropWizard Metrics (formerly Coda Hale Metrics) lib. I'm wondering why anyone would ever use this?!?

My understanding of the value of a metric is that it is real-time, accurate and relevant. If a metric is reporting a stale/cached value, of what purpose could it possibly serve?

Marishamariska answered 22/6, 2015 at 19:1 Comment(0)
S
7

Quoting the same link you added:

Cached Gauges

A cached gauge allows for a more efficient reporting of values which are expensive to calculate

What if your metric takes around two seconds seconds to calculate, or even minutes? Would you calculate every time the user request the data? Makes sense to store on a cache.

Such metric isn't what I would call real time because updating itself takes more time than rendering the information for the user. The metric is outdated already when it finishes it's calculation.

Singer answered 22/6, 2015 at 19:11 Comment(2)
Touché - thanks @Andre (+1 and green check) makes sense in that respect!Marishamariska
No problem, sometimes is hard to understand some design choices just from a manual :-)Tzong
M
0

Just a note of warning when using CachedGauge. You need to take into account the computation time when specifying the time for which you're caching that value. This is because the cache expiry period starts counting before the computation is done and it's not the cache period after the value is computed.

For example, in the example in the link which we're caching a value for 10 minutes, if loadValue() takes 5m, we're only caching it for 10m - 5m = 5 minutes.

Miscellanea answered 14/1, 2022 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.