当前位置:网站首页>A slow SQL drags the whole system down
A slow SQL drags the whole system down
2022-07-07 07:02:00 【Your little buddy】
1. Own case
A few days ago, the monitoring probe suddenly gave an alarm , Manually calling the production interface is found to be particularly slow , At ordinary times A The interface that can respond in hundreds of milliseconds in the service becomes 3-5 second , When it is slow, it takes more than ten seconds , Sometimes it just times out .
First, check the related services , Find out A service cpu And memory are normal , The service log is also output normally , Service problems are eliminated , I once thought it was the Internet that fluctuated , No reason found , Restart the service directly , The problem has not been solved .
Until later, someone said whether there was a problem with the database , Then view the database , Sure enough, I found a pile update The statement is stuck waiting for execution , Then take a look at update Of where Conditions , This field has no index , The reason is found , Because the update condition has no index , Lead to update Statements are particularly slow , The business here is batch update , In an instant, a large number of update statements will enter sql, This leads to a large consumption of database resources , Thus affecting the whole service ( This update The sentence is B service , namely B The service is slow sql It takes up a lot of database resources , This causes all other services to respond slower ).
After checking the reason, an index is added to the corresponding field , Then it gets faster , The service gradually recovers stability .( Note that the index is directly added here , At the same time, if this statement continues to enter the database, I think it may lead to locking the table , Because this business is special , Only a few people use , I call them directly to stop using , Then add the index )
Be careful : Slow here sql yes update sentence , I wanted to DBA direct kill Of , But because of update sentence DBA Dare not kill, Say you can only rollback , If it is select sentence , directly kill.
Here I have another idea is , Deactivate the interface first , Prevent a lot of update Statement continues to enter the database , Then add the index , So you can add a switch to the system , Configure whether this interface is enabled , You can start and stop an interface at any time , When something goes wrong with an interface , Just stop , Then seize the time to solve , Then enable the interface .
2. Several similar cases found on the Internet , Make a note of
1. Case study : One slow SQL Drag down the whole system
One day, I suddenly found a crazy alarm on the service detection interface 、 At the same time, the database CPU Consumption also alarm , Finally, the system cannot be accessed ;
At first, I thought there was a problem with the service , After the service is restarted, the phenomenon remains ;
After checking the database, we found , A lot of slow SQL Blocking waiting for execution :
See which tables are locked :show OPEN TABLES where In_use > 0;
Query in progress SQL, Find a lot SQL Execution blocked for hundreds of seconds
select * from information_schema.processlist where db=‘ db_xxx ‘ and info is not null;
The process of directly fetching the index ID, To assemble into kill sentence , Take it out and execute it , Kill the blocking indexing process .
select concat(‘kill ‘, id,‘;‘) from information_schema.processlist where db=‘db_xxx ‘ and info is not null;
Found that after killing once , Soon, a large number of execution blocking SQL, and 90% The above is one SQL.
kill N After that, I still can't , There will still be ......
Implement this article SQL Pick it out , For query criteria , Composite index created ,SQL The blockage disappears ,
The system has also returned to normal .....
Reference resources :MySQL Optimize 5 And CPU Consumption is too high ( One slow SQL Drag down the whole system )
边栏推荐
- 大促过后,销量与流量兼具,是否真的高枕无忧?
- How to share the same storage among multiple kubernetes clusters
- POI export to excel: set font, color, row height adaptation, column width adaptation, lock cells, merge cells
- Complete process of MySQL SQL
- From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
- 从零到一,教你搭建「CLIP 以文搜图」搜索服务(二):5 分钟实现原型
- Answer to the first stage of the assignment of "information security management and evaluation" of the higher vocational group of the 2018 Jiangsu Vocational College skills competition
- Please answer the questions about database data transfer
- Redhat5 installing vmware tools under virtual machine
- The latest trends of data asset management and data security at home and abroad
猜你喜欢

SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)

数据资产管理与数据安全国内外最新趋势
![Stack and queue-p79-10 [2014 unified examination real question]](/img/7f/e5bba2f64bb77e1781076361c32f01.jpg)
Stack and queue-p79-10 [2014 unified examination real question]

使用TCP/IP四层模型进行网络传输的基本流程

Matlab tips (30) nonlinear fitting lsqcurefit

【NOI模拟赛】区域划分(结论,构造)

FPGA课程:JESD204B的应用场景(干货分享)

Abnova 体外转录 mRNA工作流程和加帽方法介绍

. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context

Take you to brush (niuke.com) C language hundred questions (the first day)
随机推荐
MOS管参数μCox得到的一种方法
Problems and precautions about using data pumps (expdp, impdp) to export and import large capacity tables in Oracle migration
Stack and queue-p78-8 [2011 unified examination true question]
Libcurl returns curlcode description
Bus消息总线
ViewModelProvider.of 过时方法解决
Pinduoduo lost the lawsuit: "bargain for free" infringed the right to know but did not constitute fraud, and was sentenced to pay 400 yuan
Navicat importing 15g data reports an error [2013 - lost connection to MySQL server during query] [1153: got a packet bigger]
AddressSanitizer 技术初体验
From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
from . onnxruntime_ pybind11_ State Import * noqa ddddocr operation error
Maze games based on JS
2018 Jiangsu Vocational College skills competition vocational group "information security management and evaluation" competition assignment
2022/07/04学习记录
常用函数detect_image/predict
oracle如何备份索引
dolphinscheduler3. X local startup
Algorithm --- bit count (kotlin)
Anr principle and Practice
POI export to excel: set font, color, row height adaptation, column width adaptation, lock cells, merge cells