DEV Community

Hideaki Ishii
Hideaki Ishii

Posted on • Edited on

4 1

How to investigate memory usage on ElastiCache for Redis

Recently, I faced a problem which memory usage on ElastiCache for Redis becomes huge.
This post describes how we can investigate such a problem (which keys are bottlenecks on ElastiCache).

Export and download a Redis backup

At first, to analyze, we have to download the .rdb file from our ElastiCache following the official guide.

When exporting an ElastiCache backup, please be careful that the region for S3 must be the same as the one for the backup.

Analyze .rdb with redis-rdb-tools

After downloading the file, we can analyze it with redis-rdb-tools.

For example, if we wanna generate a memory report, we can do it as follows.

> rdb -c memory /var/redis/6379/dump.rdb --bytes 128 -f memory.csv
> cat memory.csv

database,type,key,size_in_bytes,encoding,num_elements,len_largest_element
0,list,lizards,241,quicklist,5,19
Enter fullscreen mode Exit fullscreen mode

If your .rdb is too large (it may be difficult to open the csv file), you could also generate a sampled report like:

> rdb -c memory /var/redis/6379/dump.rdb | ruby -ne 'print $_ if rand < 0.1' > memory.csv
Enter fullscreen mode Exit fullscreen mode

Of course, redis-rdb-tools supports features other than generating a memory report.
For more information, please see the README.

Summary

  • We can export and download a backup file easily with ElastiCache and S3.
  • We can analyze a .rdb file easily with a tool like redis-rdb-tools.

References

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs