About Redis Slow Log

Introduction

Since the slow logs are stored in memory, the read and write speeds are very fast, so there is no need to worry about performance issues due to the use of slow logs.

Available versions:> = 2.2.12
Time complexity: O (1)

How to configure

2 configuration methods. The first is to modify the redis.confconfiguration file, and the second is to use CONFIG SETdynamic modification.

Parameters to be configured:

  • slowlog-log-slower-thanConfigure to record the command whose execution time is greater than how many microseconds (microsecond, 1 second = 10 ^ 6 microseconds). The line can be set to 1000 microseconds, which is 1 millisecond.
  • slowlog-max-lenSet the maximum number of test records. Slow log itself is a first-in first-out (FIFO) queue. When the queue size exceeds the configured value, the oldest log will be deleted. Online can be set to more than 1000.

Examples:

CONFIG SET slowlog-log-slower-than 10000
CONFIG SET slowlog-max-len 128

To check whether the query is effective, you can use the CONFIG GETcommand:

127.0.0.1:6379> CONFIG GET slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "10000"

127.0.0.1:6379> CONFIG GET slowlog-max-len
1) "slowlog-max-len"
2) "128"

Query slow logs

The query is very simple, use the SLOWLOG GETcommand:

127.0.0.1:6379> SLOWLOG GET 2
1) 1) (integer) 207
   2) (integer) 1582875104
   3) (integer) 98977
   4) 1) "SPOP"
      2) "wt_pre_room_wxids"
2) 1) (integer) 206
   2) (integer) 1582875103
   3) (integer) 501649
   4) 1) "SPOP"
      2) "wt_bind_user_wxids"

If no parameters are given for this command, all slow query commands are printed out.

Now explain the meaning of the output results in the order of the result set:

    1. Unique log identifier . The unique id of the log will only be reset when the Redis server is restarted, so as to avoid repeated processing of the log.
    1. The execution time of the recorded command , expressed in UNIX timestamp format
    1. Query execution time , in microseconds
    1. Commands executed , arranged in an array

If you only need to know the current number of slow queries, use the command SLOWLOG LEN:

127.0.0.1:6379> SLOWLOG LEN
(integer) 128

Use the command SLOWLOG RESETcan clear the slow log:

127.0.0.1:6379> SLOWLOG RESET
OK

Tip: If there are many slow queries, some slow query commands may be lost. You can periodically execute the SLOWLOG GET command to persist the slow query logs to other storage (such as ES). Then make a visual interface query.

Guess you like

Origin www.linuxidc.com/Linux/2020-04/162979.htm
Recommended