Before the mid-autumn project engage in activities, users are more active SE. Redis frequently reported Timeout exception, Crazy turned over a wave of issues found that the problem is quite a lot of, the author very frequently referred to the use of Slowlog this command to troubleshoot, then the problem is coming, it is why drop?
What's a Redis slowlog?
Use this command to read or reset the Redis slow query log. In layman's words, Redis can record commands that exceed our set values, Slowlog is recorded in memory, so it's very fast.
The execution time here does not include I/O operations, such as with the client, sending the answer, etc., which is the time required to actually execute the command (the only stage of the command execution, the thread is blocked and the other requests cannot be processed concurrently).
set up Redis slowlog
Two different ways:
- can be configured by Redis.conf to finish.
Here we are mainly talking about the second way, you can use two parameters to configure slow log: Slowlog-log-slow-than *, tell Redis, record more than * microseconds in the execution of the command.
Note that setting a negative number means disabling Slowlog, while setting 0 forces the execution of each command to be logged.
Here are the instructions for setting up the Slowlog:
Redis127. 0. 0. 1: 6379>Config SetSlowlog-log-slower-than10000
"OK"
Redis127. 0. 0. 1: 6379>ConfigGetSlowlog-log-slower-than
1) "Slowlog-log-slower-than"
2) "10000"
Then the question comes again, Slowlog is recorded in the memory, if log all the command log will not be able to explode the content?
The answer is of course not. The log number of the Slowlog record has a maximum length limit, and we can query the maximum length of the Slowlog by Slowlog-max-len. The minimum value is zero. When a new command is recorded, and if it has reached its maximum length, the oldest log will be removed from the queue, FIFO.
In addition, use the Slowlog len command to view the number of records that are currently logged.
Resets the logged Slowlog information using Slowlog reset.
How to read Slowlog
We have learned that Slowlog is recorded in memory, so you can enable logging of all commands, i.e. the Slowlog-log-slow-than configuration parameter is set to 0 for easy monitoring of performance.
To read Slowlog, use the Slowlog get command, which returns each entry in a slow log. You can return only n nearest entries and pass an additional parameter to the command (for example, Slowlog GET 2).
Redis127.0. 0. 1:6379> SlowlogGet2
1)1) (integer) -//slowlog Unique identification
2) (integer)1309448221//unix time Stamp
3) (integer) the//Command execution time, unit: microseconds
4)1)"Ping"//Specific execution of the command, up to record
2)1) (integer) -
2) (integer)1309448128
3) (integer) -
4)1)"Slowlog"
2)"Get"
3)" the"
//Where Redis 4.0 and later includes the following two parts:
5)"127.0.0.1:58217"//Client Ip:port
6)"Worker-123"//Client name
Finally, it is important to note that this command requires 2.2.12 and the above version of Redis to support it.
Easy access to Redis Slowlog