Are you trying to get more information about Redis Slow Log?
This guide will help you.
The MySQL slow query log is where the MySQL database server registers all queries that exceed a given threshold of execution time.
Recently we had a customer who experienced high latency and high CPU usage with Redis operations. In such a case, Redis Slow Log is one of the best tools to debug and trace the Redis database.
Since Redis base on a single-threaded architecture, Redis Slow Log is much more useful than MySQL Slow Query Log.
In this context, we shall look into Redis Slow Log.
More about Redis slow log?
It is a system to log queries that exceeded a specified execution time. This does not include I/O operations like talk with the client, reply, and so forth, but the time to actually execute the command:
SLOWLOG subcommand [argument]
This command is available since 2.2.12 and we use it in order to read and reset the Redis slow queries log.
How to set up slow log parameters?
We can configure the slow log with two parameters:
This tells Redis what is the execution time, in microseconds, to exceed in order for the command to log.
It is the length of the slow log. The minimum value is zero. When a new command logs and the slow log is already at its maximum length, it removes the oldest one from the queue of logged commands in order to make space.
We can edit, redis.conf to do this configuration, or use the CONFIG GET and CONFIG SET commands while the server run.
In addition, it is highly effective at showing the actual processing time of each command.
How to read Slow Log?
The slow log accumulates in memory.
This makes it remarkably fast that we can enable the logging of all the commands with a minor performance hit.
Generally, we use the SLOWLOG GET command to read the slow log which returns every entry in the slow log.
It is possible to return only the N most recent entries passing an additional argument to the command (for instance SLOWLOG GET 10).
In addition, our Support Experts suggest having a recent version of redis-cli in order to read the slow log output.
redis 127.0.0.1:6379> slowlog get 2
1) 1) (integer) 14
2) (integer) 1309448221
3) (integer) 15
4) 1) “ping”
2) 1) (integer) 13
2) (integer) 1309448128
3) (integer) 30
4) 1) “slowlog”
There are also optional fields emitted only by Redis 4.0 or greater:
Every entry composes of four (or six) fields:
1. A unique progressive identifier for every slow log entry.
2. The unix timestamp at which the logged command process.
3. The amount of time for the execution, in microseconds.
4. The array composing the arguments of the command.
5. Client IP address and port (4.0 only).
6. Client name if set via the CLIENT SETNAME command (4.0 only).
We can use the entry’s unique ID in order to avoid processing slow log entries multiple times.
The ID is never reset in the course of the Redis server execution. However, a server restart can reset it.
In addition, it is possible to get the length of the slow log using the command SLOWLOG LEN.
We can reset the slow log using the SLOWLOG RESET command. Once we delete the information it is lost forever.