作者:王祥

爱可生 DBA 团队成员,主要负责 MySQL 故障处理和性能优化。对技术执着,为客户负责。

本文来源:原创投稿

*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。

背景信息

业务监控发现交易的平均响应时间比之前慢了近一倍,需要排查一下数据库是不是响应慢了。生产MySQL版本为8.0.18,一主3从半同步复制。

故障分析

首先对比查看了交易正常时段与出现异常的时段各项监控指标(cpu、qps、tps、磁盘IO等)都未发现明显的变化。接下来查看slow log发现了较多的慢SQL,而且是普通的insert语句,执行时长超过1秒。进一步观察对比发现,每次insert慢都是出现在同一秒,insert慢语句条数基本在30条左右,而且出现的间隔都是两分钟或两分钟的倍数。根据这个规律第一感觉是不是定时任务引起的问题。经过对定时任务的排查最终定位到监控脚本,监控脚本为两分钟执行一次。接下来需要排查一下,具体是哪部分导致insert慢。为了快速复现问题,直接在一个从库上使用mysqlslap进行压测。从业务那得知问题insert语句每秒会有60-80次的写入量,压测语句如下:

mysqlslap -h127.0.0.1 -uroot -p --concurrency=80 --iterations=10 --create-schema=userdb --query=/root/test.sql --engine=innodb --number-of-queries=50000#test.sql
insert into userdb.ps (clo1, clo2, clo3, clo4, clo4, clo5, clo6) values (substring(MD5(RAND()),1,20), 'fffffdddddddddd', '0', '', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaddddddddd', '2022-06-17 16:00:38.145', 34);

在压测期间执行监控脚本,一边查看slow log,能稳定复现生产的现象。通过排除法,最终定位到几个使用information_schema.processlist表的语句导致了insert慢。那information_schema.processlist为什么会导致insert慢呢?带着这个问题去查看一下官方对information_schema.processlist的描述。

The default SHOW PROCESSLIST implementation iterates across active threads from within the thread manager while holding a global mutex. This has negative performance consequences, particularly on busy systems. The alternative SHOW PROCESSLIST implementation is based on the Performance Schema processlist table. This implementation queries active thread data from the Performance Schema rather than the thread manager and does not require a mutex.

根据官方的说明:在使用默认的show processlist会持有全局互斥锁,在业务繁忙的系统上会导致性能问题。同时也给出了解决办法,使用Performance Schema中的processlist代替,此方式不会产生全局互斥锁。

performance_schema_show_processlist是MySQL 8.0.22版本引入的新功能。接下来我们来看看官方对Performance Schema中的processlist描述。

The SHOW PROCESSLIST statement provides process information by collecting thread data from all active threads. The performance_schema_show_processlist variable determines which SHOW PROCESSLIST implementation to use:
The default implementation iterates across active threads from within the thread manager while holding a global mutex. This has negative performance consequences, particularly on busy systems.The alternative SHOW PROCESSLIST implementation is based on the Performance Schema processlist table. This implementation queries active thread data from the Performance Schema rather than the thread manager and does not require a mutex.

如果开启参数performance_schema_show_processlist,show processlist使用Performance Schema中的processlist避免了全局互斥锁的问题,如果不开启该参数则show processlist使用information_schema.processlist会产生全局锁。

在配置文件[mysqld]下加上performance_schema_show_processlist=on配置。配置完成后,查看performance_schema下的processlist。

root@localhost:mysql.sock [(none)]> show variables like 'performance_schema_show_processlist';
+-------------------------------------+-------+
| Variable_name                       | Value |
+-------------------------------------+-------+
| performance_schema_show_processlist | ON    |
+-------------------------------------+-------+
#信息与information_schema.processlist下保持一致
root@localhost:mysql.sock [(none)]> select * from performance_schema.processlist\G
*************************** 1. row ***************************ID: 5USER: event_schedulerHOST: localhostDB: NULL
COMMAND: DaemonTIME: 354STATE: Waiting on empty queueINFO: NULL
*************************** 2. row ***************************ID: 8USER: rootHOST: localhostDB: NULL
COMMAND: QueryTIME: 0STATE: executingINFO: select * from performance_schema.processlist
2 rows in set (0.00 sec)

总结

1.使用MySQL 8.0.22之前的版本,在业务繁忙的敏感系统上执行show processlist需要谨慎。

2.使用MySQL 8.0.22之后版本, 可以开启performance_schema_show_processlist避免该问题。但依旧不建议频繁查询会话信息。

另外查询processlist表导致MySQL 实例crash问题,请参考文章:https://mp.weixin.qq.com/s/qRc6mGk4_jvc2rHBIKojiQ

参考:

https://dev.mysql.com/doc/refman/8.0/en/performance-schema-processlist-table.html

https://dev.mysql.com/doc/refman/8.0/en/performance-schema-system-variables.html#sysvar_performance_schema_show_processlist

故障分析 | show processlist 引起的性能问题相关推荐

  1. MySQL processlist的state属性详解

    关于processlist其他属性介绍,可查看之前的文章:MySQL性能分析 - (二) processlist使用及重要指标说明 state属性是processlist中分析性能的关键部分. 通过官 ...

  2. 罗小波 mysql_千金良方——MySQL性能优化金字塔法则

    基  础  篇 第1章  MYSQL初始化安装.简单安全加固  3 1.1  背景  3 1.2  初始化安装  3 1.2.1  下载二进制安装文件  3 1.2.2  创建MYSQL用户  3 1 ...

  3. oracle dba入门线路图--记某培训公司的ORACLE DBA技能进阶实战大纲

    博主注:给oracle dba入门者的一点建议,个人也收藏一个. ORACLE DBA技能进阶实战 一.新手入行须知 首先了解DBA这个职业,再决定要不要做DBA:如果要做DBA,怎么才能做好DBA: ...

  4. 监控系统选型,这篇不可不读

    作者 | 骆俊武 责编 | 王晓曼 来源 | IT人的职场进阶(ID:BestITer) 之前,我写过几篇有关「线上问题排查」的文章,文中附带了一些监控图,有些读者对此很感兴趣,问我监控系统选型上有没 ...

  5. zabbix监控哪些东西_监控系统选型,一篇全搞定

    之前,写过几篇有关线上问题排查的文章,文中附带了一些监控图,有些读者对此很感兴趣,问我监控系统选型上有没有好的建议? 图片来自 Pexels 目前我所经历的几家公司,监控系统都是自研的.其实业界有很多 ...

  6. 监控系统选型,这篇不可不读!

    之前,我写过几篇有关「线上问题排查」的文章,文中附带了一些监控图,有些读者对此很感兴趣,问我监控系统选型上有没有好的建议? 目前我所经历的几家公司,监控系统都是自研的.其实业界有很多优秀的开源产品可供 ...

  7. 企业级监控平台,监控系统选型

    企业级监控平台,监控系统选型 一.监控基础知识 1.1 监控系统的7大作用 1.2 使用监控系统的正确姿势 1.3 监控的对象和指标都有哪些? 1.4 监控系统的基本流程 1.5 监控目标 1.6 监 ...

  8. 三种网络仿真软件:OPNET、NS和GloMoSim

    作用 网络仿真主要应用在2 个方面: 一是开发和评价新的网络协议和设备, 二是网络规划设计. 网络仿真能迅速建立起网络模型, 方便地修改模型, 适用于预测网络性能.容量规划.故障分析.端到端性能分析. ...

  9. join left loke mysql_MySQL 使用经验

    在索引中完成排序 SELECT thread_id FROM thread_5 WHERE id = 11074781 AND status = 0 AND thread_type = 0 ORDER ...

最新文章

  1. Java学习总结:57(Properties子类)
  2. 多条SQL语句同时执行方法
  3. shuoj 418 丢史蒂芬妮(素数筛+sg函数)
  4. 协议开发 中移动CMPP2.0协议API(三)
  5. 为客户端加入输入线程
  6. Spring开发包介绍
  7. 如何创建newsstand应用程序
  8. Hello Blazor:(1)像ASP.NET WebForm一样写代码
  9. dw怎么打开html模板,Dreamweaver中如何使用模板
  10. IIS网站或系统验证码不显示问题——使用了托管的处理程序,但是未安装或未完整安装 ASP.NET...
  11. Java集合系列---红黑树(基于HashMap 超详细!!!)
  12. 编程语言对比 with
  13. OpenCV安装与第一个程序
  14. Safe handle has been closed异常的原因及解决思路
  15. 万年历c语言程序微博,简易的万年历程序C语言
  16. JavaScript 运输公司计算运费,路程越远,运费的折扣越高
  17. 【Optimal Path】星门跳跃 链表+SPFA
  18. 语义网络 语义网 词汇链 知识图谱辨析
  19. P3426 [POI2005]SZA-Template(kmp、dp)
  20. NB无信号以及无法连接网络问题分析及解决

热门文章

  1. flutter 九宫格菜单_Flutter页面开发体验
  2. 前端js入门——JavaScript 转义字符串
  3. 1.5 微型计算机的操作系统
  4. OpenCV入门基础操作(二)----图像像素的处理
  5. fading是恶之首
  6. 关于R-Squre应用的8个建议
  7. scheduleAtFixedRate 与 scheduleWithFixedDelay 的区别
  8. Traceroute 原理分析
  9. KVM虚拟化技术介绍及搭建
  10. 只需6行代码,将PPT转为Word!就可以解放我们的双手