加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql数据库磁盘io高的排查是怎样的

发布时间:2022-01-13 15:03:45 所属栏目:MySql教程 来源:互联网
导读:mysql数据库磁盘io高的排查是怎样的,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。 最近,数据库会报磁盘IO高的告警,但是cpu不高。 故障 ● 主机名称: xxxx ● 告警信息: Disk I/O is
       mysql数据库磁盘io高的排查是怎样的,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
 
     最近,数据库会报磁盘IO高的告警,但是cpu不高。
 
故障
● 主机名称: xxxx
● 告警信息: Disk I/O is overloaded on xxxx
● 告警时间: 2020.04.10-13:09:06
● 主机地址: xxxxxx
● 当前状态: 36.14 %
 
   数据库磁盘io高时,执行的sql如下:
 
2527 | xxxx | 172.xxxx:35072 | xxxx | Query | 0 | update | insert ignore into `xxxxannotations` (`trace_ |
 
| 2528 |xxxn | 172.xxxx:37270 | xxxx | Query | 0 | update | insert ignore into `xxxxannotations` (`trace_id`, `s
 
| 2530 | xxxx | 172.xxxx:44210 | xxxx | Query | 0 | update | insert into `xxxx_spans` (`trace_id`, `id`, `debug`, `start_ts`, `name
 
| 2531 |xxxx | 172.xxxx:45910 | xxxx | Query | 0 | query end | insert ignore into `xxxx_annotations`4', ', -1408108278, 8031) |
 
| 2532 | xxx | 172.xxxx:58890 | xxxx | Sleep | 0 | | NULL
 
    也就是数据库会批量的执行insert ignore into 语句。
 
mysql> show engine innodb status G
 
---TRANSACTION 1557551308, not started flushing log
 
---TRANSACTION 1557551309, not started flushing log
 
---TRANSACTION 1557551310, not started flushing log
 
---TRANSACTION 1557551311, not started flushing log
 
---TRANSACTION 1557551313, not started flushing log
 
---TRANSACTION 1557551304, not started flushing log
 
............
 
 
    可以看到,每个事务都在flushing log中,说明刷redo log比较慢。可能是redo log 比较小。
 
mysql> show variables like '%innodb_log_file_size%';
 
+----------------------+----------+
 
| Variable_name | Value |
 
+----------------------+----------+
 
| innodb_log_file_size | 50331648 |
 
+----------------------+----------+
 
1 row in set (0.00 sec)
 
   事实证明,innodb_log_file_size确实比较小,才50M,建议增大至2个4G。
 
   继续分析:
 
mysql> show engine innodb status G
 
--------
 
FILE I/O
 
--------
 
..........
 
Pending flushes (fsync) log: 1; buffer pool: 0
 
1 pending preads, 0 pending pwrites
 
................
 
LOG
 
---
 
Log sequence number 988322448590
 
Log flushed up to 988322444468
 
Pages flushed up to 988311239867
 
Last checkpoint at 988309561881
 
1 pending log writes, 0 pending chkp writes
 
23371463 log i/o's done,  132.33 log i/o's/second
 
    上述看到log thread 挂起的fsync()操作数据为1,说明log thread刷盘有等待。
 
    另外,last checkpoint落后于log flushed up to太多,接近于redo log文件的大小,这时会触发innodb疯狂刷redo,从而导致磁盘io高,对性能影响非常糟糕。
 
    还有,这个数据库的innodb buffer pool也很小,使用的默认值为128M,也需要调大。
 
   优化方法:
 
        设置innodb_log_file_size=4G,设置innodb_buffer_pool_size=4G。
 
        经过观察,数据库磁盘io高、cpu不高的问题消失。
 
看完上述内容,你们掌握mysql数据库磁盘io高的排查是怎样的的方法了吗?

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读