Monitoring Slow Redis Calls

Fahim Sakri
2 min readApr 21, 2017

--

Being a backend developer, you will always come across profiling the code. If you are looking to figure out the bottleneck in your python code, checkout @timeit article. Here we will figure out the slow redis queries by monitoring them.

Redis provides us with monitor feature which let us inspect slow queries. Slowlog will log last X amount queries which took more time than Y microseconds to run. You can set this either in redis.conf or at runtime using CONFIG command

CONFIG SET slowlog-log-slower-than 5000
CONFIG SET slowlog-max-len 50

The slowlog-log-slower-than specified above is specified in microseconds, that means it will log all the queries taking time above 5 ms.

To Retrieve the slowlog queries, you have to use SLOWLOG GET X. Where X is the number of slow queries you want to retrieve.

SLOWLOG GET 50

Result will display a unique id, timestamp, time taken to execute the query in microseconds, and the actual command + parameter executed.

1) 1) (integer) 0        ## unique id
2) (integer) 1491042367 ## timestamp
3) (integer) 11498 ## time taken
4) 1) "KEYS" ## command
2) 'r:usr:*' ## command paramter
3) “0”

Hope, this will help you figure out the heavy queries. You can also reset the log using SLOWLOG RESET.

Other articles

P.S. Thanks for reading this far! If you found value in this, I’d really appreciate it if you recommend this post (by clicking the ❤ button) so other people can see it!.

--

--