×


Redis Slow Log - More about it

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.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Redis queries.

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:


1. slowlog-log-slower-than

This tells Redis what is the execution time, in microseconds, to exceed in order for the command to log.


2. slowlog-max-len

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.


Output format:

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”
2) “get”
3) “100”

There are also optional fields emitted only by Redis 4.0 or greater:

5) “127.0.0.1:58217”
6) “worker-123”


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.


[Need help with the Redis Slow Log? We are available 24*7. ]


Conclusion

This article covers how Redis Slow Log works. Redis Slow #Log is one of the best tools to debug and trace the Redis database. 

The Redis Slow Log is a system to log queries that exceeded a specified execution time. 

The execution time does not include I/O operations like talking with the client, sending the reply and so forth, but just the time needed to actually execute the command (this is the only stage of command execution where the thread is blocked and can not serve other requests in the meantime).


You can configure the slow log with two parameters: 

1. slowlog-log-slower-than tells Redis what is the execution time, in microseconds, to exceed in order for the command to get logged. Note that a negative number disables the slow log, while a value of zero forces the logging of every command. 

2. slowlog-max-len is the length of the slow log. The minimum value is zero. When a new command is logged and the slow log is already at its maximum length, the oldest one is removed from the queue of logged commands in order to make space.


Redis Slow Log configuration can be done by editing redis.conf or while the server is running using the CONFIG GET and CONFIG SET commands.

Available since 2.2.12.

This #command is used in order to read and reset the Redis slow queries log.


Redis slow log overview

The #Redis Slow Log is a system to log queries that exceeded a specified execution time. 

Slowlog, as its name, is used to record commands whose execution time exceeds limitation (a little slow).

The execution time does not include I/O operations like talking with the client, sending the reply and so forth, but just the time needed to actually execute the command (this is the only stage of command execution where the thread is blocked and can not serve other requests in the meantime).

The Redis SLOWLOG is used to help identify queries which are taking too long to execute.


You can configure the slow log with two parameters:

slowlog-log-slower-than tells Redis what is the execution time, in microseconds, to exceed in order for the command to get logged. Note that a negative number disables the slow log, while a value of zero forces the logging of every command. slowlog-max-len is the length of the slow log. The minimum value is zero. When a new command is logged and the slow log is already at its maximum length, the oldest one is removed from the queue of logged commands in order to make space.


The configuration can be done by editing redis.conf or while the server is running using the CONFIG GET and CONFIG SET commands.