We run a farm of Redis instances for storing real time analytics. Because Redis stores objects in memory, it happens to be an extremely fast way to retrieve data; thus, most of our charts and graphs pull data from various Redis instances that contain desired data.
Our Redis boxes are running in AWS on m2.2xlarge instances, which contain a bit over 30GB of memory. Every once in awhile, it’s helpful to get an idea of how much memory various key patterns are consuming because we hold over 20GB across several hundred thousand keys in some cases. There’s a nifty gem dubbed redis-audit (my fork of it adds Bundler) that is quite helpful in painting a broad picture of memory usage across a sampling of key patterns.
Redis-audit works by sampling a configurable portion of keys residing in a Redis database. It then prints out a report of key patterns that delineates, among other things, memory usage. The summary portion of the output report looks something like:
You can also get more details on individual key patterns; for example, the key above using 19% of Redis’s memory is detailed like so:
redis-audit details for a key pattern
==============================================================================Found 27 keys containing hashs, like:
These keys use 19.03% of the total sampled memory (990 bytes)14.81% of these keys expire (4), with maximum ttl of 28 days, 15 hours, 51 minutes, 20 seconds
Average last accessed time: 69 days, 19 hours, 14 minutes, 15 seconds - (Max: 95 days, 23 hours, 10 minutes, 10 seconds Min:1 days, 8 hours, 8 minutes, 40 seconds)
This data is helpful in a number of ways; for instance, we discovered that a significant portion of memory was being consumed by keys containing old time series data that for some reason did not have associated TTLs. Thus, we were able to achieve that particular data (into MongoDB) and free up memory.
If you want to understand how memory is distributed across key patterns in a Redis instance, then I think you’ll find Redis-audit quite helpful!