当前位置:网站首页>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 .
边栏推荐
- leetcode 72. Edit distance edit distance (medium)
- Prosperity is exhausted, things are right and people are wrong: where should personal webmasters go
- Redis入门完整教程:慢查询分析
- Redis入门完整教程:Redis Shell
- Postgresqlql advanced skills pivot table
- 攻防世界 misc 高手进阶区 a_good_idea
- Redis入门完整教程:Pipeline
- Li Kou 98: verify binary search tree
- 啃下大骨头——排序(二)
- LOGO special training camp section I identification logo and Logo Design Ideas
猜你喜欢

Logo special training camp Section V font structure and common design techniques

MySQL Architecture - logical architecture

LOGO特训营 第五节 字体结构与设计常用技法

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 II collocation relationship between words and graphics

Attack and defense world misc advanced area ditf

业务太忙,真的是没时间搞自动化理由吗?

Redis入门完整教程:客户端通信协议

【室友用一局王者荣耀的时间学会了用BI报表数据处理】
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
随机推荐
Practice and principle of PostgreSQL join
The table is backed up in ODPs. Why check m in the metabase_ Table, the logical sizes of the two tables are inconsistent, but the number of
[roommate learned to use Bi report data processing in the time of King glory in one game]
Logo special training camp section 1 Identification logo and logo design ideas
Attack and defense world misc advanced grace-50
High school physics: linear motion
串口数据帧
How to reset the password of MySQL root account
leetcode 72. Edit distance edit distance (medium)
Persistence mechanism of redis
测试必会:BUG的分类及推进解决
Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
LOGO特训营 第四节 字体设计的重要性
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
Attack and defense world misc advanced area can_ has_ stdio?
MYSQL架构——逻辑架构
攻防世界 MISC 进阶区 hit-the-core
POM in idea XML dependency cannot be imported
Sword finger offer 68 - I. nearest common ancestor of binary search tree
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface