Redis-configuration slow query

What is slow query?

A query whose internal execution time exceeds a specified time limit is called a slow query.

How to set the specified time limit

There are two fields in the Redis configuration file:
Insert picture description here
slowlog-log-slower-than: The unit of this configuration item is microseconds, and the default is 10000 microseconds, which is 10 milliseconds. Commands whose execution time exceeds this time are slow queries, but slow The query only records the execution time of the command, and does not include the command queuing and network transmission time, so the actual command execution time will only be greater than or equal to the slow query time, and then these slow queries are added to the log file.

slowlog-max-len: Set the maximum number of logs. The default is 128. The server uses a first-in-first-out method to save slow query logs. Once the slow log has reached the specified upper limit, when new logs come in, The oldest slow log will be deleted first. Therefore, it is recommended to increase the number of slow logs, such as 1000, and then it is best to persist slow logs regularly to prevent old data from being overwritten by new data.

Operation example

Since the service must be restarted to take effect after modifying the configuration file, it is recommended to use dynamic configuration to modify the slow query configuration items. First understand the following commands:

 config set slowlog-log-slower-than xxx:设置慢查询时间
 config set slowlog-max-len xxx:设置最大慢日志数量
 config rewrite:把修改的配置持久化到配置文件中
 slowlog get[n]:获取慢查询队列
 slowlog len:获取慢查询队列的长度
 slowlog reset:清空慢查询队列

The slow query time is specified as 0 microseconds, redis save all commands executed, as follows:
Insert picture description here
enter a few commands, as follows:
Insert picture description here
by slowlog getviewing the slow log results are as follows:
Insert picture description here
Take a meaning to explain under which each row represents a:
Insert picture description here

The first line: the unique identifier of the log. The
second line: the UNIX timestamp when the command is executed. The
third line: the execution time of the command, in microseconds. The
fourth line: the command and its parameters, arranged in an array

By slowlog len: acquiring slow query queue length, as
Insert picture description here
by slowlog resetemptying the queue slow queries, as follows:
Insert picture description here
In this case there will be a slow query queue a log, the log is recorded slowlog reset command.

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/108559926
Recommended