Redis slow query log

Redis slowlog is what

redis those of slow log record length exceeds the predetermined execution time of the request. Execution time does not include the I / O operations (such as a network communication with the client), but the actual execution time of the command ( the thread during will be blocked and can not serve other requests )

There are two configuration parameters for slow log: 

It would help--log-slowlog Within last : setting execution time, in milliseconds, longer than the time at which command execution will be credited to the log. -1 means records slow log; 0 records all commands force. 

max-len-slowlog : the slow log length. The minimum value is 0. If the log queue has exceeded the maximum length, the oldest record will be removed from the queue. 

More than two parameters can be configured by editing redis.conf file. Running the redis, by config get, config set command to dynamically change the parameters of the two

Use this command to read or reset Redis slow query log. Popular talk is redis command can take longer than the set value of our record, slowlog is recorded into memory, oh, so very fast.

Set Redis slowlog

In two ways:

  1. It can be accomplished by configuring redis.conf.
  2. Runtime, use and CONFIG SET CONFIG GET command configuration.

Here we are mainly talking about the second way, you can use two parameters to configure the slow log: slowlog-log-slow-than *, tell Redis, recording more than *  microseconds  command within the implementation.

Note that a negative number disables slowlog, and set up the implementation of the mandatory 0 records for each command.
The following are slowlog setup instructions:

redis 127.0.0.1:6379>config set slowlog-log-slower-than 10000
"OK"

redis 127.0.0.1:6379>config get slowlog-log-slower-than
1)  "slowlog-log-slower-than"
2)  "10000"

So the question again, slowlog is then recorded in memory, if all of the command log records the contents will explode it?

The answer is of course not. The number of log slowlog record is the maximum length limit, we can query the maximum length slowlog by slowlog-max-len. Minimum is zero. When a new command is recorded, and if it has reached the maximum length of a log oldest deleted from the queue, FIFO.

In addition, the use of slowlog len command to view the current number recorded. 
Use slowlog reset reset slowlog recorded information.

How to Read slowlog

We already know slowlog is recorded in memory, so you can enable logging all commands that is slowlog-log-slow-than configuration parameter is set to 0 to facilitate the monitoring of performance.

To read slowlog, use SLOWLOG GET get command, which returns slow log of each entry. Can return only the N most recent entry, passing an additional parameter to the command (e.g. SLOWLOG GET 2).

redis 127.0.0.1:6379> slowlog get 2
    1) 1) (integer) 14             //slowlog 唯一标识
       2) (integer) 1309448221     //unix 时间戳
       3) (integer) 15             //命令执行的时间,单位:微秒
       41"ping"                //具体执行的命令,最多记录128
    21) (integer) 13
       2) (integer) 1309448128
       3) (integer) 30
       41"slowlog"
          2"get"
          3"100"

//其中 Redis 4.0 及以上版本还包含以下两部分:

       5"127.0.0.1:58217"         //客户端IP:Port
       6"worker-123"              //客户端名称

Finally, note that this command requires 2.2.12 or later of redis to support.

 

Guess you like

Origin www.cnblogs.com/wjoyxt/p/11428899.html