当前位置:网站首页>Redis introduction complete tutorial: slow query analysis
Redis introduction complete tutorial: slow query analysis
2022-07-04 22:52:00 【Gu Ge academic】
Many storage systems ( for example MySQL) Provide slow query logs to help developers and operation and maintenance personnel set
Slow operation of bit system . The so-called slow query log is that the system calculates each life before and after the command execution
Execution time of order , When the default threshold is exceeded , This command will be the relevant information ( for example : occurs
between , Time consuming , Command details ) recorded ,Redis It also provides a similar function .
Pictured 3-1 Shown ,Redis A command executed by the client is divided into the following 4 Parts of :
1) dispatch orders
2) Order to line up
3) Command execution
4) Return results
We need to pay attention to , Slow query only counts steps 3) Time for , So no slow query doesn't mean customers
There is no timeout problem on the client .
3.1.1 Two configuration parameters of slow query
For slow query function , Two things need to be clear :
· How to set the preset threshold ?
· Slow query where records are stored ?
Redis Provides slowlog-log-slower-than and slowlog-max-len Configuration to solve these two problems
problem . It can be seen from the literal meaning that ,slowlog-log-slower-than That's the preset threshold ,
It's in microseconds (1 second =1000 millisecond =1000000 Microsecond ), The default value is 10000, If hold
OK, one “ Very slowly ” The order of ( for example keys*), If its execution time exceeds 10000 tiny
second , Then it will be recorded in the slow query log .
Operation and maintenance tips
If slowlog-log-slower-than=0 All orders will be recorded ,slowlog-log-slower-
than<0 No command is recorded .
Literally ,slowlog-max-len It just shows how much slow query logs can be stored at most
strip , It doesn't say where it's stored ? actually Redis A list is used to store slow query days
Records ,slowlog-max-len Is the maximum length of the list . When a new command satisfies the slow query condition
Inserted into this list , When the slow query log list is at its maximum length , First inserted
A command will be removed from the list , for example slowlog-max-len Set to 5, When there is a second 6 Slow query
Insert the words , Then the first data at the head of the team will be listed , The first 6 A slow query will be listed .
stay Redis There are two ways to modify the configuration , One is to modify the configuration file , The other is to make
use config set Command dynamic modification . For example, use config set The order will slowlog-log-slower-
than Set to 20000 Microsecond ,slowlog-max-len Set to 1000:
config set slowlog-log-slower-than 20000
config set slowlog-max-len 1000
config rewrite
If you want to Redis Persistent configuration to local configuration file , You need to perform config rewrite life
Make , Pictured 3-2 Shown .
Although the slow query log is stored in Redis In the memory list , however Redis Did not expose this
Key of a list , But through a set of commands to achieve the slow query log access and management . Below
Shao these orders .
(1) Get slow query log
slowlog get [n]
The following operation returns the current Redis The slow query , Parameters n You can specify the number :
127.0.0.1:6379> slowlog get
1) 1) (integer) 666
2) (integer) 1456786500
3) (integer) 11615
4) 1) "BGREWRITEAOF"
2) 1) (integer) 665
2) (integer) 1456718400
3) (integer) 12006
4) 1) "SETEX"
2) "video_info_200"
3) "300"
4) "2"
...
You can see that each slow query log has 4 Attributes make up , They are the identification of the slow query log
id、 Occurrence timestamp 、 The command takes time 、 Execute commands and parameters , The slow query list is shown in the figure 3-3 Shown .
(2) Get the current length of the slow query log list
slowlog len
for example , At present Redis There is 45 Slow query :
127.0.0.1:6379> slowlog len
(integer) 45
(3) Slow query log reset
slowlog reset
It's actually cleaning up the list , for example :
127.0.0.1:6379> slowlog len
(integer) 45
127.0.0.1:6379> slowlog reset
OK
127.0.0.1:6379> slowlog len
(integer) 0
3.1.2 Best practices
The slow query function can effectively help us find Redis Possible bottlenecks , But in reality
Pay attention to the following points during use :
·slowlog-max-len Configuration suggestions : It is suggested to enlarge the slow query list online , When recording slow queries
Redis Will truncate long commands , It doesn't take up a lot of memory . Increasing the slow query list can
Slow down the possibility of slow queries being eliminated , For example, online can be set to 1000 above .
·slowlog-log-slower-than Configuration suggestions : Default value exceeds 10 MS is judged as slow query ,
Need basis Redis The amount of concurrency adjusts the value . because Redis Using single thread response command , For high flow
The scene of quantity , If the command is executed at 1 Milliseconds or more , that Redis Support at most OPS Less than
1000. So for high OPS Of the scene Redis Recommended setting is 1 millisecond .
· Slow queries only record command execution time , Command queuing and network transmission time are not included . because
The execution time of this client will be longer than the actual execution time of the command . Because the command execution queue machine
system , Slow queries can cause other command cascades to block , So when the client has a request timeout , It needs to be checked
Check whether there is a corresponding slow query at this time point , So we can analyze whether it is the command cascade caused by slow query
Blocking .
· Because slow query log is a FIFO queue , In other words, if there are many slow queries
Under the circumstances , Some slow query commands may be lost , To prevent this from happening , On a regular basis
perform slow get Command to persist slow query logs to other stores ( for example MySQL), then
You can make a visual interface to query , The first 13 This chapter introduces Redis Private cloud CacheCloud Provide
This function , Good tools can get twice the result with half the effort .
边栏推荐
- 攻防世界 MISC 进阶 glance-50
- Practice and principle of PostgreSQL join
- [Lua] Int64 support
- Microservices -- Opening
- [roommate learned to use Bi report data processing in the time of King glory in one game]
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { fmt.Pri
- LOGO special training camp section I identification logo and Logo Design Ideas
- 啃下大骨头——排序(二)
- 共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
- Lost in the lock world of MySQL
猜你喜欢
LOGO特訓營 第三節 首字母創意手法
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
Install the gold warehouse database of NPC
Redis入门完整教程:客户端通信协议
It is said that software testing is very simple, but why are there so many dissuasions?
10 schemes to ensure interface data security
Redis入门完整教程:Redis Shell
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
Redis入门完整教程:慢查询分析
sobel过滤器
随机推荐
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
Analog rocker controlled steering gear
Solana chain application crema was shut down due to hacker attacks
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
High school physics: linear motion
LOGO特训营 第二节 文字与图形的搭配关系
Unity-VScode-Emmylua配置报错解决
Logo Camp d'entraînement section 3 techniques créatives initiales
剑指 Offer 67. 把字符串转换成整数
On-off and on-off of quality system construction
攻防世界 misc 进阶区 2017_Dating_in_Singapore
SPSS安装激活教程(包含网盘链接)
LOGO特訓營 第一節 鑒別Logo與Logo設計思路
Erik baleog and Olaf, advanced area of misc in the attack and defense world
Three stage operations in the attack and defense drill of the blue team
LOGO特训营 第三节 首字母创意手法
新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
蓝队攻防演练中的三段作战