当前位置:网站首页>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
边栏推荐
- Three effective strategies for the transformation of data supply chain to be coordinated and successful
- Hcia-r & s self use notes (21) STP technical background, STP foundation and data package structure, STP election rules and cases
- Restful interface specification
- Will the approval in advance affect the formal approval?
- 沟通中经常用到的几个库存术语
- Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)
- Custom type
- Interview questions of Bank of Hangzhou [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- 每周招聘|PostgreSQL数据库研发工程师,年薪60+,名企高薪,挑战自我!
- 2022年物联网行业有哪些用例?
猜你喜欢

PostgreSQL and Navicat: the backbone of the database industry

逆袭黑马:数据库全栈工程师(DevDBOps)培训,把最好的课程送给您!

华裔科学家Ashe教授对涉嫌造假的Nature论文的正面回应

你知道磁环电感的常见磁芯类型有哪些吗?

Database full stack Engineers (devdbops) have low down payment and high return, and pay after employment

Science | 华盛顿大学利用AI和结构预测设计全新蛋白质

An online accident, I suddenly realized the essence of asynchrony
![[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version](/img/70/5638080a2d2eabf6ae1f2a8db3abe6.png)
[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version
![[postgresql]postgresqlg使用enerate_series() 函数补全统计](/img/62/893986eb97a61f4e9ef32abc8d2a90.png)
[postgresql]postgresqlg使用enerate_series() 函数补全统计

Reinforcement learning weekly 55: lb-sgd, msp-drl & robust reinforcement learning against
随机推荐
sql多表查询的练习
Practical project: boost search engine
The most classic Nature paper on Alzheimer's disease is suspected of fraud
[untitled]
2022年物联网行业有哪些用例?
Learn various details and thoughts of chatroom implementation in Muduo
如何使用数据管道实现测试现代化
Cloud native microservices Chapter 1 server environment description
Hcia-r & s self use notes (18) campus network architecture foundation, switch working principle, VLAN principle
The secret weapon of apple iphone11 series: U1 chip may usher in the era of ultra wideband
HCIA-R&S自用笔记(19)VLAN配置及实验、VLAN间路由
Interview questions of Bank of Hangzhou [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Hcia-r & s self use notes (19) VLAN configuration and experiment, routing between VLANs
SQL multi table query exercise
2019 biometric forum successfully ended: these ten highlights should not be missed!
面试官问:JS的this指向
8 other programming languages -- Recording
Sign up now | frontier technology exploration: how to make spark stronger and more flexible
Several inventory terms often used in communication
A13 processor has become the biggest highlight of iphone11 series: its performance is twice that of Kirin 980!