Redis Slow Query Log helps developers and operations staff locate slow operations that exist in the system. Slow query log is that the system calculates the execution time of each command before and after the execution of the command. When it exceeds the preset threshold value, it records the relevant information of the command (slow query ID, occurrence timestamp, time consumption, detailed information of the command).

It should be noted that the slow query log only counts the execution time of the command in Step 3), so slow queries do not mean that the client does not have timeout issues. It should be noted that the slow query log only counts the execution time of the command in Step 3), so slow queries do not mean that the client does not have timeout issues.

1, slow query configuration parameters: The default threshold for slow queries slowlog-log-slower-than slowlog-log-slower-than slower is the default threshold, in microseconds. The default value is 10000. If a command takes more than 10000 subseconds to execute, it will be recorded in the slow query log. If the value of slowlog-log-slower than is 0, all commands are logged. If the value of slowlog-log-slower than is less than 0, no command will log.

Slowlog-max-len The slowlog-max-len length only indicates the maximum number of slowlog-max-len entries. Redis uses a list to store slow query logs, where showlog-max-len is the maximum length of the list. When the slow query log reaches the maximum length of the list and another slow query log enters the list, the log that was first inserted into the list will be removed from the list and the new log will be inserted at the end of the list.

A slow query log consists of four attributes: ID, timestamp, command elapsed time, command execution, and parameters

SlowLog [n] command: slowLog get [n] SlowLog get [n] command: slowLog get [n] SlowLog get [n

It is recommended that the list of slow query logs be increased in the online environment. Redis truncates long commands when recording slow query logs, and does not consume a large amount of memory. Increasing the list of slow queries reduces the likelihood that slow queries will be dropped from the list. For example, online can be set to 1000 or more.

The setting of slowlog-loglower-than suggests that this value need to be adjusted according to the amount of concurrency in Redis. Due to www.walajiao.comredis’s single-threaded response reputation, Redis can support less than 1000 OPS (operations per second) at most for high traffic scenarios if the command execution time is more than 1 millisecond, so the Redis recommendation for high OPS scenarios is set to 1 millisecond.

Slow query only records the command execution time and does not include the command queuing time and network transmission time. Therefore, the execution time of the client command is longer than the actual execution time of the Redis server. Because of the extreme queue of command execution, slow query will cause command cascading blocking. Therefore, when the client request timeout occurs, it is necessary to check whether there is a corresponding slow query at that time point, so as to analyze whether the command cascading blocking is caused by the slow query

Slow query log is a slow query queue with many slow queries, and some slow query commands may be lost. Slow get command can be performed regularly to persist the slow query log to other storage. Then make a visual interface query.