In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How do I find blocked commands through slow queries? To solve this problem, today the editor summarizes this article about redis blocking, hoping to help more students who want to learn redis to find a more simple and easy way.
Like Mysql, Redis has slow query records. When the execution time of a command exceeds the set value, the command is recorded in the slow query list. Through slow query, we can improve our program. Prevent redis blocking.
Configuration
There are two configuration parameters for slow query:
Slowlog-log-slower-than
Slowlog-max-len
Slowlog-log-slower-than is used to set a threshold in subtleties, with a default value of 10000, or 10 milliseconds.
When the value is set to less than 0, no commands are recorded
When the value is equal to 0, all commands are recorded.
Slowlog-max-len represents the maximum number of records, which defaults to 128. for example, if it is set to 10, when the 11th slow query is inserted, the data at the head of the line will be dequeued.
These two configurations also support dynamic configuration, and you can set the value of slow-log-slower-than to a higher value when the number of visitors is not very high at the beginning of the project. When the traffic is getting larger and larger, you may need to reduce its value. But we don't want to stop the redis service, so we can modify the configuration dynamically.
127.0.0.1 6379 > config set slowlog-log-slower-than 1000OK # online modify configuration 127.0.0.1 6379 > config rewriteOK# persists the modified configuration to the configuration file
Operation and maintenance advice: when the traffic is large, we generally recommend setting the slowlog-log-slower-than to 1000, or less. When this value is 1000, it means that redis can support up to 1000 concurrency.
Slow query view
The slow query view of redis is different from mysql, and there are special commands for redis view.
Get slow query log
Slowlog get [n], n represents the number of entries. Default is 10.
127.0.0.1 slowlog get1 6379 > 1) (integer) 18004 2) (integer) 1589424642 3) (integer) 50 4) 1) "slowlog" 2) "get" 5) "127.0.1 integer" 5) "2) (integer) 18003 2) (integer) 1589423805 3) (integer) 47 4) 1)" slowlog "2)" get "5) "127.0.0.1 purl 58364" 6) ".
The first parameter is the log identification id number
The second one is the occurrence timestamp.
The third is the time of execution of the command (subtle)
The last one is the commands and parameters.
Get the length of the slow query
Slowlog len
127.0.0.1 6379 > slowlog len (integer) 128
Clear the slow query list
127.0.0.1 purl 6379 > slowlog resetOK
Persist the slow query log to mysql
Because the length of redis is limited, it will be lost in the case of a lot of slow queries. We can regularly go to redis to retrieve the list of slow query records and persist it to mysql to prevent this from happening.
The pseudo code is as follows:
While (true) {$slowlen = $redis- > slowlog ('len'); $slowlogs = $redis- > slowlog (' get',$slowlen); $insSql = "INSERT INTO slowlog (exec_time,run_time,command) VALUES"; if (is_array ($slowlogs) & & count ($slowlogs)) {foreach ($slowlogs as $slowlog) {$execTime = $slowlog [2]; $runTime = $slowlog [1] $command = implode (', $slowlog [3]); $insSql. = "('$execTime','$runTime','$command'),";} $flag = mysqli_query ($mysqli, substr ($insSql, 0,-1)); if ($flag) {$redis- > slowlog ('reset');}} unsleep (10000);}
The above is through the slow query to find the blocking command method introduction, the detailed use of their own use to know the specific points. If you want to read more related articles, you are welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.