数据库管理,  系统运维

mysql 负载高一直降不下来的原因排查

现象:
mysql服务器 24核48线程,内存64G,CPU load 一直稳定在8左右,mysqlCPU 占用800% ,update 语句并发很多,一个简单的update与需要1到2秒甚至有一些到5秒以上都有,业务出现登录响应比较长等问题。

一开始以为是查询量比较大引起了高负载,结果上线了proxysql 实现读写分离后,数据库主库负载依旧没有降下来,show processlist 发现很多日志库写入都需要十几秒,于是把部分日志库给剥离出去,负载是有降下来一些,业务登录有所缓和,但数据库主库服务器负载依旧保持在7左右,已经凌晨1点多了,先睡觉了。
第二天上午发现负载依旧保持7左右,一直没降下来,于是分析了所有主库的语句,归类为insert 和 update语句,明显update语句是比较多的,占70%,且update时间都需要1到5秒甚至更长。

参考了:https://blog.csdn.net/gt9000/article/details/87980128

mysql -e “show engine innodb status\G” > /tmp/innodb.log
show engine innodb status
---TRANSACTION 0, not started sleeping before entering InnoDB
mysql tables in use 1, locked 0
MySQL thread id 4064419019, OS thread handle 0x7f9c48912700, query id 52162825462 10.35.25.45 425_user statistics
select `pid_key` from `partner` where (`pid_number` = '105444') limit 1
---TRANSACTION 22475503717, not started sleeping before entering InnoDB
mysql tables in use 1, locked 0
MySQL thread id 4064419018, OS thread handle 0x7f9c40164700, query id 52162825443 10.35.25.45 425_user Sending data
select `user_regtime` from `user_main_first_login` where `user_name` = 'cp123456cp' and `user_pid` = '105879' limit 1
---TRANSACTION 0, not started sleeping before entering InnoDB
mysql tables in use 1, locked 1

通过日志看出很多表处于锁的状态,且—TRANSACTION 0, not started sleeping before entering InnoDB ,也就是很多事物都未进入innodb,都在排队。这时去检查innodb的相关参数,发现:
innodb_thread_concurrency = 8 ,低于服务器的核心数,后面在线改成innodb_thread_concurrency = 24,负载就下降了。

留言

您的电子邮箱地址不会被公开。 必填项已用*标注

闽ICP备20008591号-1