现象:从库延迟高,查看slave status发现sql_thread执行语句的速度比主库慢,这样的延迟会一直高下去,下面是排查的一些过程
1. 检查了从库的配置,磁盘的写入速度的确没有主库高
2. iostat -m 1 10查看磁盘写入 ,从库为2M/S,主库也就3M/S,从库磁盘没主库高,但这个档次的速度应该不影响
3. 将sync_binlog从1设置为,0,3,10,100 无效果,innodb_flush_log_at_trx_commit的值为2
4. 增加slave_parallel_workers的值,无效果
5. 然后又排查了内存相关参数,没有明显不合理的地方
6. 最后要从binlog中解析SQL,看看执行的都是哪些SQL,哪些表,在从binlog抽取SQL之前,查看了一下 show full processlist,看到了 System lock

然后就重启了一下slave,这是个作为备份用的从库,业务不访问,当时没有考虑锁的问题,应该再排查一下,有没有其他锁

解决方法为重启一下slave;

>show full processlist;
+---------+-------------+-----------+-------------+---------+---------+---------------------------------------------+--------------------------------------------------------------------------------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+---------+-------------+-----------+-------------+---------+---------+---------------------------------------------+--------------------------------------------------------------------------------------------+-----------+---------------+
| 1 | system user | | NULL | Connect | 2698858 | Waiting for master to send event | NULL | 0 | 0 |
| 2 | system user | | NULL | Connect | 0 | Waiting for dependent transaction to commit | NULL | 0 | 0 |
| 3 | system user | | NULL | Connect | 67873 | System lock | UPDATE......... |

stop slave;
start slave;

>show full processlist;
+---------+-------------+-----------+-------------+---------+-------+---------------------------------------------+-----------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+---------+-------------+-----------+-------------+---------+-------+---------------------------------------------+-----------------------+-----------+---------------+
| 3506710 | root | localhost | ad_dianjing | Query | 0 | starting | show full processlist | 0 | 0 |
| 3508115 | system user | | NULL | Connect | 53 | Waiting for master to send event | NULL | 0 | 0 |
| 3508116 | system user | | NULL | Connect | 0 | Waiting for dependent transaction to commit | NULL | 0 | 0 |
| 3508117 | system user | | NULL | Connect | 56827 | System lock | NULL | 0 | 0 |
| 3508118 | system user | | NULL | Connect | 56828 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508119 | system user | | NULL | Connect | 56828 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508120 | system user | | NULL | Connect | 56977 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508121 | system user | | NULL | Connect | 56981 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508122 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508123 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508124 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508125 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508126 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508127 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508128 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508129 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508130 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508131 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
| 3508132 | system user | | NULL | Connect | 57852 | Waiting for an event from Coordinator | NULL | 0 | 0 |
+---------+-------------+-----------+-------------+---------+-------+---------------------------------------------+-----------------------+-----------+---------------+
19 rows in set (0.00 sec)

Seconds_Behind_Master: 54622
然后就可以看到Seconds_Behind_Master的数值以每秒100的速度往下降

System lock的产生原因分析可以参考下面这篇文章
http://blog.itpub.net/7728585/viewspace-2149659

my16_sql_thread执行慢导致主从延迟高的一个情景的更多相关文章

  1. mysql主从延迟高的原因

    1.1.1故障1:从库数据与主库冲突 1 2 3 4 5 6 show slave status; 报错:且show slave status\G Slave_I/O_Running:Yes Slav ...

  2. MySQL 主从延迟几万秒 Queueing master event to the relay log(转)

    数据库版本Server version:    5.6.24-log Source distribution 问题描述 数据采集平台业务数据库由于批量灌数据导致主从延迟上万秒. 复制线程长期处于Que ...

  3. 面试官:咱们来聊一聊mysql主从延迟

    背景 前段时间遇到一个线上问题,后来排查好久发现是因为主从同步延迟导致的,所以今天写一篇文章总结一下这个问题希望对你有用.如果觉得还不错,记得加个关注点个赞哦 思维导图 思维导图 常见的主从架构 随着 ...

  4. mysql主从延迟

    1. MySQL数据库主从同步延迟原理.要说延时原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作,主 库对所有DDL和DML产生binlog,binlog是顺序写,所 ...

  5. 一次线上MySQL主从延迟排查

    今天早上来上班,发现zabbix一直告警主从延迟,mysql slave Seconds_Behind_Master (mysql.slave_status[Seconds_Behind_Master ...

  6. 深入理解Mysql数据库主从延迟

    1什么会增加主从延迟? 1 网络不好 2 从库硬件差 3 索引没做好,从库执行慢 4 从库锁等待,多见于myisam 5 主库写频繁,从库单线程执行慢 6 使用row复制,或mix使用行复制 2如何优 ...

  7. 减少MySQL主从延迟的神器--并行复制大揭密

    1. 简介 MySQL 5.6引入了基于schema的并行复制,即如果binlog events操作的是不同schema的对象,不是DDL,且操作的对象没有对其他schema的foreign key关 ...

  8. MySQL主从延迟如何解决?

    我们知道生产环境中经常会遇到MySQL主从延迟问题,从原理上也能看出主库的事务提交是并发模式,而从库只有一个SQL线程负责解析,所以本身上就可能存在延迟. 延迟的主要原因在于: 1.从库的配置往往没有 ...

  9. OGG复制进程延迟高,优化方法一(使用索引)

    日常运维过程中,可能发现OGG同步进程延迟很高: 本篇介绍其中的一种方式. OGG复制进程,或者说同步进程及通过解析ogg trail文件,输出dml语句,在目标库执行dml操作,那么延迟高可能性其一 ...

随机推荐

  1. go语言的源码文件的分类及含义

    Go源码文件:名称以.go为后缀,内容以Go语言代码组织的文件 多个Go源码文件是需要用代码包组织起来的 源码文件分为三类:命令源码文件.库源码文件(go语言程序) 测试源码文件(辅助源码文件) 命令 ...

  2. Opencv Laplacian(拉普拉斯算子)

    #include <iostream>#include <opencv2/opencv.hpp>#include <math.h> using namespace ...

  3. 面试题: Struts2

    1. Struts2与Struts1的联系与区别是什么?为什么要用Struts2? 答案: struts1与struts2都是mvc框架的经典实现模式. Struts2不是从Struts1升级而来,而 ...

  4. wpf仿qq边缘自动停靠,支持多屏

    wpf完全模仿qq边缘自动隐藏功能,采用鼠标钩子获取鼠标当前状态,在通过当前鼠标的位置和点击状态来计算是否需要隐藏. 以下是实现的具体方法: 一.鼠标钩子实时获取当前鼠标的位置和点击状态 /// &l ...

  5. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-006BitonicMax

    package algorithms.analysis14; import algorithms.util.StdOut; import algorithms.util.StdRandom; /*** ...

  6. 算法Sedgewick第四版-第1章基础-007一用两个栈实现简单的编译器

    1. package algorithms.util; import algorithms.ADT.Stack; /****************************************** ...

  7. 如何使用EditPlus将json格式字符串默认为UTF-8格式

    1.首先用EditPlus打开json格式的文件 2.选择Tools工具栏下的Configure  User Tools 3.点击左侧File 4.在右侧Default encoding中选择UTF- ...

  8. 100085G GCD Guessing Game

    传送门 题目大意 给定一个数N,现在又一个数x,在1~N之间,现在每次可以猜一个数a,返回gcd(x,a),问说最少猜几次可以确定x. 分析 这个题应该可以算是贪心,但是没人知道这样为啥是对的(雾), ...

  9. 100741A Queries

    传送门 题目 Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my f ...

  10. Mac安装破解版Office 2016办公软件

    一.相关软件 Microsoft Office 2016 For Mac Cracker 破解工具 资源地址(链接:https://pan.baidu.com/s/1Z5CIv-XbxS08MniYN ...