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:
|
|
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!
This story, "Sampling Redis keys for memory consumption" was originally published by JavaWorld.