Redis slow query log preliminary understanding

first question:

The slow query log is to record redis command requests whose execution time exceeds a given length of time

second question:

Let users better monitor and find some slow redis operations in the business and find better optimization methods

In Redis, there are two settings for slow queries-the maximum timeout for slow queries and the maximum number of logs for slow queries.

1. You can set the slow query time limit by modifying the configuration file or directly entering the following command in the interactive mode. When this time is exceeded, the query record will be added to the log file.

CONFIG  SET  slowlog-log-slower-than  num

Set how many more subtle queries are slow queries, and add these slow queries to the log file. The unit of num is milliseconds. The default slow query of redis under windows is 10,000 microseconds, which is 10 milliseconds.

2. You can limit the number of slow query logs stored in the log by setting the maximum number. The command for this setting in interactive mode is as follows:

CONFIG  SET  slowlog-max-len  num

Set the maximum number of logs, num has no unit value, and the default number of slow query log records for redis under windows is 128.

Analysis of the command:

The CONFIG command will cause the redis client to find the .conf configuration file of redis by itself, find the corresponding configuration item and modify it.

The above is to configure redis in interactive mode, which is no different from modifying the configuration line directly in the .conf file. Both can implement the above slow query logging function, but it should be noted that the interaction on the client side Enter the CONFIG SET command in the mode to perform logging settings only for the current session. For other sessions (restart the redis server), then it is the same as the default settings of the redis.conf file? Why is this so? Because redis is based on memory, when one exits a client, all settings will be returned to the default version. The next time you want to set the slow query log configuration, you still need to retype the command. What about modifying the configuration in the .conf file? This method is relatively easy once and for all, because every time the server is started is based on the configuration file, so the slowlog log will default to the settings in the .conf file as the standard.

Even so, when doing some tests, individuals prefer to modify directly in interactive mode. Modifying in interactive mode can open the redis client in the current state and later (under the condition that the server has not been restarted) will execute slow queries Log recording function. If you modify the configuration items in the .conf file, you need to restart the redis server to make this function take effect. Next time you need to modify the configuration, you will also get the .conf file to reconfigure.

For a more complete description of the configuration file process, I will write here how to modify the configuration items in the .conf file

Use Notepad under Windows operating system, and use Sublim Text or Vim under Linux operating system to open. turn up

Corresponding below will find the configuration options

So, how do you view slow queries next?

In the interactive mode, the command is very simple.

SLOWLOG GET

(Of course, lowercase can also be used, the redis client does not have too strict restrictions on case)

Take windows as an example to view the records as follows

For the convenience of explanation, I set the timeout time to 0 milliseconds and the log record to 1

So what do 1) 2) 3) 4) in the record indicate?

1) Indicates the log unique identifier uid

2) The time stamp of the system when the command is executed

3) The length of the command execution is calculated in subtle

4) Commands and command parameters

When doing log query, you can check the specific command running time by 3) (Note: once again, the unit of time is subtle, but for an insert operation, 10,000 microseconds, which is 10 milliseconds or 0.01 seconds. Can be considered a slow operation) Which operation has a problem. Of course, this is limited to test use. If you need to insert redis into the slow query event, you need to check the persistent log generated by redis. This requires additional configuration. This involves clustering and distribution. .

Guess you like

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