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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay