Hasura Enterprise Edition exports Prometheus metrics related to caching which can provide valuable insights into the efficiency and performance of the caching system. This can help towards monitoring and further optimization of the cache utilization.
The graphql engine exposes the
hasura_cache_request_count Prometheus metric.
It represents a
counter and is incremented every time a request with
@cached directive is served.
It has one label
status, which can have values of either
|request served from the cache|
|request served from the source (not found in cache)|
Get insights from metrics
hasura_cache_request_count metric can be used to get insights into the cache utilization by calculating the hit-miss ratio.
The hit-miss ratio is the ratio of the number of requests served from the cache to the total number of requests.
hit-miss ratio = hit count / (hit count + miss count)
What does the hit-miss ratio tells us?
Cache Efficiency: The hit-miss ratio reflects how well the caching system can serve requests from its cache. A higher hit ratio indicates more efficient cache usage, as more requests are being served from the cache rather than requiring fetching data from the upstream data source.
Cache Performance: The hit-miss ratio is a measure of cache performance. A higher hit ratio generally indicates better cache performance as it reduces latency and improves overall system performance.
The metrics can be visualized using a tool like Grafana.
- Total requests per minute with
hitrequests per minute:
missrequests per minute:
- Hit-Miss ratio over lifetime: