|
Today middleware interfaces response time is very long, generally after investigation, it found that access Redis is slow, and the cpu Redis has indeed risen to about 98%, and now need to locate the problem. The first open redis slowlog.
What is SLOWLOG
Slow log Redis is used to record the query execution time logging system.
Query execution time is the response does not include things like client (talking), and other IO operations to send a reply, and just execute a query time-consuming.
In addition, slow log stored in memory inside, read and write very fast, so you can safely use it, do not worry because open slow log detriment Redis speed.
Slow log behavior is specified by two configuration parameters (configuration parameter), and CONFIG commands CONFIG can modify them dynamically by overwriting files or redis.conf.
The first option is slowlog-log-slower-than, it decided to execution time is greater than the number of microseconds (microsecond, 1 second = 1,000,000 microseconds) queries recorded.
For example, execute the following command to make slow log records all queries time is greater than or equal to 100 microseconds query:
CONFIG set slowlog-log-slower-than 100
The following command logs all queries longer than 1000 microseconds query:
CONFIG set slowlog-log-slower-than 1000
Another option is slowlog-max-len, it decided to slow log can hold the maximum number of logs, slow log itself is a LIFO queue, when the queue size exceeds slowlog-max-len, one of the oldest log will be deleted, and the latest to join a log to slow log, and so on.
The following command allows slow log store up to 1000 log:
CONFIG get slowlog-max-len
Using the CONFIG command to query the current value of the two options
View slow log
To view the slow log, you can use SLOWLOG GET or SLOWLOG GET number command, the former print all slow log, the maximum length depends on the value slowlog-max-len option, and SLOWLOG number only print the specified number of logs.
The latest log will be the first to be printed
Unique id log in Redis server restart only time will reset to avoid repetitive processing of logs (for example, you might want to send e-mail notification every time you discover a new slow query).
Check the number of the current log
Using the command SLOWLOG can see the number of the current log.
Please note that the value of this distinction and slower-max-len, which is the number of a current log, a record of the number of allowed maximum log.
redis> SLOWLOG LEN
(Integer) 14
Clear log
Using the command SLOWLOG RESET can be emptied slow log.
redis> SLOWLOG LEN
(Integer) 14
redis> SLOWLOG RESET
redis> SLOWLOG LEN
(Integer) 0
By slow log can be found in the program using keys message_ * command, leading middleware long response time to modify the code troubleshooting. |
|
|
|