当前位置:网站首页>Positioning of soaring problems caused by online MySQL CPU
Positioning of soaring problems caused by online MySQL CPU
2022-07-26 23:25:00 【I'm tired of eating, but I'm not fat】
problem
One day, I suddenly received an alert email , The server CPU Threshold exceeded , And has been consistently high
The analysis reason
- Use
htopView resource consumption , according to CPU Usage is in descending order , All the discoveries are mysqld Process occupation CPU Very high - Get into mysql Command line
show processlist;View the currently executing commands , After many executionsshow processlistFound several fixed sql It's been implemented , And the parameters passed each time are different
mysql> show processlist;
+--------+------+-------------------+--------------------------+---------+------+--------------+-----------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+------+-------------------+--------------------------+---------+------+--------------+-----------------------------------------------------------------------------------------------+
| 130878 | root | localhost:43314 | bomconfig | Sleep | 77 | | NULL |
| 132762 | root | localhost:34342 | ccsx_weibao | Query | 0 | Sending data | SELECT vir.*, 1 as business_type
FROM ccsx_data.v_install_record vir
WHERE vir.id = 1948 |
| 132841 | root | localhost:42218 | ccsx | Sleep | 574 | | NULL |
| 132955 | root | localhost:54332 | ccsx | Sleep | 693 | | NULL |
| 133058 | root | localhost:38132 | bomconfig | Sleep | 434 | | NULL |
| 133243 | root | localhost:58272 | ccsx_data | Sleep | 539 | | NULL |
| 133347 | root | localhost:41100 | ccsx_weibao | Query | 0 | Sending data | select * from ccsx_weibao.install_record_accessory where host_id=2106 |
| 133416 | root | localhost:47832 | international_ccsx_data | Sleep | 519 | | NULL |
| 133454 | root | localhost:51226 | internatinal_ccsx_weibao | Sleep | 1194 | | NULL |
| 133459 | root | localhost:51642 | ccsx | Sleep | 1 | | NULL |
| 133466 | root | localhost:51956 | bomconfig | Sleep | 488 | | NULL |
| 133467 | root | localhost:51958 | bomconfig | Sleep | 77 | | NULL |
| 133469 | root | localhost:52616 | ccsx_data | Sleep | 540 | | NULL |
| 133519 | root | localhost:57874 | ccsx_weibao | Query | 0 | Sending data | SELECT vir.*, 1 as business_type
FROM ccsx_data.v_install_record vir
WHERE vir.id = 19042 |
After the first 2 Step execution , Guess someone is for The query is called in the loop , Different parameters are passed each time
In order to confirm the correctness of my analysis , Copy
show processlistThe results of the sql, Go to the project code query , Finally, the following code is traced , Indeed, queries are used in the loop ,fuck!@Override public List<InstallRecordVO> getInstalls(List<Integer> ids) { List<InstallRecordVO> installRecords = new ArrayList<>(); if (CollectionUtil.isNotEmpty(ids)){ ids.forEach(t->{ InstallRecordVO installRecordVO = installRecordMapper.queryById(t); if(installRecordVO!=null){ List<InstallRecordAccessory> installRecordAccessories = installRecordAccessoryMapper.queryByHostId(installRecordVO.getId()); //…… Omitted code List<SysFile> sysFileList = sysFileMapper.queryByBusinessInfo(paramMap); //…… Omitted code } }); } return installRecords; }Just having the above code is not completely sure , This loop has been running online , So I decided to use arthas To further determine , So I put arths attach Use on projects in the production environment
traceTrack the three queries in the loop respectively , See if it is being implemented , As a result, all three are being implemented , It confirms that the cycle has been executing , therefore cpu Here's the problem .
trace com.sonoscape.ccs.data.mapper.InstallRecordMapper queryById -n 5 --skipJDKMethod false
trace com.sonoscape.ccs.data.mapper.InstallRecordAccessoryMapper queryByHostId -n 5 --skipJDKMethod false
trace com.sonoscape.ccs.data.mapper.SysFileMapper queryByBusinessInfo -n 5 --skipJDKMethod false
- Finally, I found the person in charge of this part of the code , His ids The parameter should have been filtered , Not much in theory , As a result, the query results in ids It's actually full table , spit
Conclusion
Don't easily execute in a loop sql
边栏推荐
- SQL 基础知识
- Eureka基本使用
- 蔚来杯2022牛客暑期多校训练营2
- ESMFold: AlphaFold2之后蛋白质结构预测的新突破
- After working for one year, I have some insights (written in 2017)
- 基于gRPC编写golang简单C2远控
- 数据供应链的转型 协调一致走向成功的三大有效策略
- Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
- Six challenges facing enterprise data governance!
- Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)
猜你喜欢

SQL Basics

PostgreSQL 与 Navicat:数据库行业的中坚力量

研究阿尔茨海默病最经典的Nature论文涉嫌造假
![[H5 bottom scrolling paging loading]](/img/2c/fb8dd8a7d985392450ad7d3b70016c.png)
[H5 bottom scrolling paging loading]

数据供应链的转型 协调一致走向成功的三大有效策略

PostgreSQL and Navicat: the backbone of the database industry

数据库全栈工程师(DevDBOps)低首付、高回报,先就业后付款

Reinforcement learning weekly 55: lb-sgd, msp-drl & robust reinforcement learning against

第二部分—C语言提高篇_11. 预处理

JSON formatting gadget -- pyqt5 instance
随机推荐
Easily implement seckill system with redis! (including code)
New employees of black maredge takeout
Domestic DRAM will be mass produced by the end of the year, but the road ahead is still long!
C language dynamic memory management
Public cloud security and compliance considerations
Hcia-r & s self use notes (21) STP technical background, STP foundation and data package structure, STP election rules and cases
Learn various details and thoughts of chatroom implementation in Muduo
8-其他编程语言--记录
Database full stack Engineers (devdbops) have low down payment and high return, and pay after employment
Incremental secure file system SFS based on C language design
蔚来杯2022牛客暑期多校训练营2
Hcia-r & s self use notes (20) VLAN comprehensive experiment, GVRP
Reduce power consumption and upgrade functions! Qiyingtailun released the second generation voice AI chip: the module price is as low as 14.99 yuan!
[shaders realize distorted outline effect _shader effect Chapter 2]
Problems and solutions encountered in using nextline(), nextint() and next() in scanner
Download win10 system image and create virtual machine on VMware virtual machine
The nature and proof of the center of gravity of [mathematics] tree
Kt6368a Bluetooth chip development precautions and problem collection - long term update
Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
json格式化小工具--pyqt5实例