RedisInsight, a free GUI for Redis, allows you to identify and troubleshoot bottlenecks with the Slowlog analysis tool. If you are experiencing high latency and high CPU usage with Redis operations and looking for a tool for debugging and tracing your Redis database, RedisInsight Slow Log is a perfect tool for you.
Redis Slow Log is highly effective at showing the actual processing time of each slow command. The Redis slowlog is a log of all commands which exceed a specified run time. Please note that the network latency is not included in the measurement, just the time taken to actually execute the command. Redis Slow Log is a list of slow operations for your Redis instance.
Follow the below steps to see how Slowlog is leveraged to troubleshoot performance issues.
Follow https://developer.redislabs.com/create to install and create Redis database
To install RedisInsight on your local system, you need to first download the software from Redis Labs website.
Click this link to access a form that allows you to select the operating system of your choice.
Run the installer. After the web server starts, open http://YOUR_HOST_IP:8001 and add a Redis database connection.
Select "Connect to a Redis database"
Enter the requested details, including Name, Host (endpoint), Port, and Password. Then click “ADD REDIS DATABASE”.
There are two configurations related to slowlog query -
- slowlog-log-slower-than: Used to set the evaluation time of slow query, that is to say, commands that exceed this configuration item will be treated as slow operations and recorded in the slow query log. Its execution unit is microseconds (1 second equals 1000000 microseconds);
- slowlog-max-len: Used to configure the maximum number of records in the slow query log.
Please note that a negative number disables the slowlog, while a value of zero forces the logging of every command. Slowlog-max-len is the length of the slowlog. The minimum value is zero. When a new command is logged and the slowlog 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.
Slowlog will log the last X number(amount) of queries which took more time than Y microseconds to run. You can set this either in redis.conf or at runtime using CONFIG command
To see slowlog in action, let us pick up a large dataset. Create a file called importcities.py and add the below content:
Create a file called config.py as shown below:
Ensure that you provide the right host and port details.
Execute the script:
You will see the below results:
If you want to simulate slowlogs, then consider using KEYS command. It is always recommended NOT TO USE KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.
The KEYS command may ruin performance when it is executed against large databases
Let us try to run KEYS * in RedisInsight CLI and see if it generates slowlog as shown below:
Run it one more time and you will notice below:
Try decreasing the execution time(50 ms), and you will notice that the below run query also gets logged into the slowlog
Each entry in the slowlog contains four fields: a slowlog entry ID, the Unix timestamp of when the command was run, the execution time in microseconds, and an array with the command itself, along with any arguments. See the example output below:
In order to retrieve the slowlog queries, you have to use SLOWLOG GET X. Where X is the number of slow queries you want to retrieve.
As shown above, the result displays a unique id, timestamp, time taken to execute the query in microseconds, and the actual command + parameter executed. It is important to note that the Slow log is transient; there's no persistence for it so in the case of failover, the slowlog is lost. If you are looking to rely on a persistent slowlog, you'll be wanting to reconsider your design choices
Please note: If I choose “0” it forces the logging of every command while “-1” disabled the slowlog.
In a clustered database, each node can have different values for slowlog. You will need to use the configuration tool in order to configure slowlog for clustered databases.
- Explore Redis keys using RedisInsight browser tool
- Memory Analysis using RedisInsight
- Unified Search and Analytics using RediSearch Browser Tool
- Managing time-series data using RedisTimeSeries Browser Tool
- Analyze Your Redis commands using RedisInsight Profiler tool
- Debugging Redis using RedisInsight Slowlog Tool
- Using Redis Streams with RedisInsight