当前位置:网站首页>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 .
边栏推荐
- How to send a reliable request before closing the page
- Redis入门完整教程:发布订阅
- 繁华落尽、物是人非:个人站长该何去何从
- 串口数据帧
- POM in idea XML dependency cannot be imported
- Solana chain application crema was shut down due to hacker attacks
- [cooking record] - stir fried 1000 pieces of green pepper
- 醒悟的日子,我是怎么一步一步走向软件测试的道路
- High school physics: linear motion
- leetcode 72. Edit distance edit distance (medium)
猜你喜欢
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
Persistence mechanism of redis
MySQL Architecture - user rights and management
醒悟的日子,我是怎么一步一步走向软件测试的道路
The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展
攻防世界 misc 进阶区 2017_Dating_in_Singapore
攻防世界 MISC 进阶区 Ditf
How to send a reliable request before closing the page
The overview and definition of clusters can be seen at a glance
Hit the core in the advanced area of misc in the attack and defense world
随机推荐
Analysis of environmental encryption technology
Redis入门完整教程:慢查询分析
页面关闭前,如何发送一个可靠请求
Tla+ introductory tutorial (1): introduction to formal methods
Redis入门完整教程:有序集合详解
Redis入门完整教程:GEO
Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
Talk about Middleware
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Persistence mechanism of redis
常用技术指标之一文读懂BOLL布林线指标
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
Gnawing down the big bone - sorting (II)
[roommate learned to use Bi report data processing in the time of King glory in one game]
【OpenGL】笔记二十九、抗锯齿(MSAA)
Redis入门完整教程:HyperLogLog
Lost in the lock world of MySQL