当前位置:网站首页>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 .
边栏推荐
- Locust performance test - environment construction and use
- md5工具类
- Close system call analysis - Performance Optimization
- 通过Go语言创建CA与签发证书
- Shell script implements application service log warehousing MySQL
- 攻防世界 misc 高手进阶区 a_good_idea
- LOGO special training camp section I identification logo and Logo Design Ideas
- 新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码
- Postgresqlql advanced skills pivot table
- Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
猜你喜欢
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
质量体系建设之路的分分合合
Install the gold warehouse database of NPC
攻防世界 MISC 进阶区 3-11
MySQL Architecture - user rights and management
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
Logo special training camp Section IV importance of font design
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
Close system call analysis - Performance Optimization
[OpenGL] note 29 anti aliasing (MSAA)
随机推荐
Unity-VScode-Emmylua配置报错解决
攻防世界 misc 进阶区 2017_Dating_in_Singapore
Hit the core in the advanced area of misc in the attack and defense world
PMO: compare the sample efficiency of 25 molecular optimization methods
LOGO特训营 第三节 首字母创意手法
Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
环境加密技术解析
MYSQL架构——逻辑架构
攻防世界 MISC 进阶区 Ditf
剑指 Offer 67. 把字符串转换成整数
How diff are the contents of the same configuration item in different environments?
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
Google Earth engine (GEE) -- take modis/006/mcd19a2 as an example to batch download the daily mean, maximum, minimum, standard deviation, statistical analysis of variance and CSV download of daily AOD
The difference between Max and greatest in SQL
Sobel filter
醒悟的日子,我是怎么一步一步走向软件测试的道路
Li Kou 98: verify binary search tree
LOGO特訓營 第三節 首字母創意手法
Solana chain application crema was shut down due to hacker attacks