Talk about redis slowlog and latency monitor



This article mainly studies redis slowlog and latency monitor


Redis introduced slowlog in version 2.2.12 to record commands that exceed the specified execution time. This execution time does not include IO operation time such as communication with the client, which is the actual command execution time. The main operations are as follows:

View the number of slowlog> slowlog len
(integer) 1024

View slowlog execution time threshold> config get slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "1000"

Set the slowlog execution time-consuming threshold.> config set slowlog-log-slower-than 1000

See the threshold for the number of slowlog saves.> config get slowlog-max-len
1) "slowlog-max-len"
2) "1024"

Set the threshold for the number of slowlog saves.> config set slowlog-max-len 1024

Query slowlog> slowlog get 1
1) 1) (integer) 76016
   2) (integer) 1537250266
   3) (integer) 48296
   4) 1) "COMMAND"

The first line is the command id, the second line is timestamp, the third line is the execution time, and the fourth line is the command and parameters

Clear slowlog record> slowlog reset

latency monitor

Redis introduced latency monitoring in version 2.8.13, which mainly monitors latency spikes (Delay glitch)。 It monitors based on the event mechanism. command event is the latency of monitoring command execution, fast-command event is the latency of monitoring commands with time complexity of O(1) and O(logN), and fork event is the latency of redis execution system call fork(2). The main operations are as follows:

Set up/open latency monitor> config set latency-monitor-threshold 100

Read latency monitor configuration> config get latency-monitor-threshold
1) "latency-monitor-threshold"
2) "100"

Get the latest latency> debug sleep 1
(1.01s)> debug sleep .25
OK> latency latest
1) 1) "command"
   2) (integer) 1537268070
   3) (integer) 250
   4) (integer) 1010

Returns the event name, timestamp of occurrence, latest delay (Millisecond), maximum delay (Millisecond)

View the delay history of an event> latency history command
1) 1) (integer) 1537268064
   2) (integer) 1010
2) 1) (integer) 1537268070
   2) (integer) 250

View event delay diagram> latency reset command
(integer) 0> debug sleep .1
OK> debug sleep .2
OK> debug sleep .3
OK> debug sleep .4
OK> debug sleep .5
(0.50s)> latency graph
(error) ERR syntax error> latency graph command
command - high 500 ms, low 100 ms (all time high 500 ms)


Reset/Empty Event Data> latency reset command
(integer) 1> latency history command
(empty list or set)> latency latest
(empty list or set)

Diagnostic advice> latency doctor
Dave, I have observed latency spikes in this Redis instance. You don't mind talking about it, do you Dave?

1. command: 6 latency spikes (average 257ms, mean deviation 142ms, period 3.83 sec). Worst all time event 500ms.

I have a few advices for you:

- Check your Slow Log to understand what are the commands you are running which are too slow to execute. Please check for more information.
- Deleting, expiring or evicting (because of maxmemory policy) large objects is a blocking operation. If you have very large objects that are often deleted, expired, or evicted, try to fragment those objects into multiple smaller objects.


  • Redis’ slowlog was introduced in version 2.2.12 and latency monitor was introduced in version 2.8.13
  • Slowlog only records the execution time of pure commands, excluding IO interaction with clients and fork of redis
  • Latency spikes monitored by latency monitor have a wider scope, including not only command execution, but also the time-consuming operations such as fork(2) system call and key expiration.