早上接到open-falcon报警,一台mysql从库同步延迟2w多秒,mysql版本比较老,用的5.1.37。

连接从库查找原因:

  

show processlist一下,查看哪些线程在跑。

看到Time=25565,也就是说这个线程保持当前状态25565秒,一直在执行Updating操作。怀疑是由php分析数据脚本引起的,把这条语句发给开发,问问执行的是什么操作,开发说是每个用户登录,游戏角色等级提高就执行一次update操作,又问开发有没有脚本执行这个update语句,开发也说不清。。没办法,只能去脚本机搜索定时任务中php脚本了,脚本非常多crontab -l 列出所有脚本,配合awk,grep搜索所有php脚本,然后过滤脚本中内容update,有几个是有update操作的,逐个分析,并查看脚本记录的日志。执行tail -f /opt/wwwroot/daemon/run/datasource/newdata/fast_channel_run.log时,发现了大量update的记录,又向开发确认下,原因基本确定,让开发优化php脚本了。

解决思路:

  给开发提建议,优化程序逻辑,多个update合成一条语句执行。

降低update频率

  升级mysql版本,mysql-5.1性能比新版差的太多,但短期不现实。

  实在延迟跟不上了,重做了salve。

下面是show processlist的一些说明,摘自官方文档。

13.7.5.30. SHOW PROCESSLIST Syntax

SHOW [FULL] PROCESSLIST

SHOW PROCESSLIST shows you which threads are running. You can also get this information from the INFORMATION_SCHEMA PROCESSLIST table or the mysqladmin processlist command. If you have the PROCESS privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account that you are using). If you do not use the FULL keyword, only the first 100 characters of each statement are shown in the Info field.

Process information is also available from the performance_schema.threads table. However, access to threads does not require a mutex and has minimal impact on server performance. INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST have negative performance consequences because they require a mutex. threads also shows information about background threads, which INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST do not. This means that threads can be used to monitor activity the other thread information sources cannot.

The SHOW PROCESSLIST statement is very useful if you get the “too many connections” error message and want to find out what is going on. MySQL reserves one extra connection to be used by accounts that have the SUPER privilege, to ensure that administrators should always be able to connect and check the system (assuming that you are not giving this privilege to all your users).

Threads can be killed with the KILL statement. See Section 13.7.6.4, “KILL Syntax”.

Here is an example of SHOW PROCESSLIST output:

mysql> SHOW FULL PROCESSLIST\G
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db: NULL
Command: Connect
Time: 1030455
State: Waiting for master to send event
Info: NULL

The columns produced by SHOW PROCESSLIST have the following meanings:

  • Id

    The connection identifier.

  • User

    The MySQL user who issued the statement. If this is system user, it refers to a nonclient thread spawned by the server to handle tasks internally. This could be the I/O or SQL thread used on replication slaves or a delayed-row handler. unauthenticated user refers to a thread that has become associated with a client connection but for which authentication of the client user has not yet been done. event_scheduler refers to the thread that monitors scheduled events. For system user, there is no host specified in the Host column.

  • Host

    The host name of the client issuing the statement (except for system user where there is no host). SHOW PROCESSLIST reports the host name for TCP/IP connections in host_name:client_port format to make it easier to determine which client is doing what.

  • db

    The default database, if one is selected, otherwise NULL.

  • Command

    The type of command the thread is executing. For descriptions for thread commands, see Section 8.12.5, “Examining Thread Information”. The value of this column corresponds to the COM_xxx commands of the client/server protocol and Com_xxx status variables. See Section 5.1.6, “Server Status Variables”

  • Time

    The time in seconds that the thread has been in its current state.

  • State

    An action, event, or state that indicates what the thread is doing. Descriptions for State values can be found at Section 8.12.5, “Examining Thread Information”.

    Most states correspond to very quick operations. If a thread stays in a given state for many seconds, there might be a problem that needs to be investigated.

    For the SHOW PROCESSLIST statement, the value of State is NULL.

  • Info

    The statement the thread is executing, or NULL if it is not executing any statement. The statement might be the one sent to the server, or an innermost statement if the statement executes other statements. For example, if a CALL statement executes a stored procedure that is executing a SELECT statement, the Info value shows the SELECT statement.

转载于:https://www.cnblogs.com/xiaoming279/p/6224837.html

MySQL主从同步延迟相关推荐

  1. 深入解析Mysql 主从同步延迟原理及解决方案

    深入解析Mysql 主从同步延迟原理及解决方案 参考文章: (1)深入解析Mysql 主从同步延迟原理及解决方案 (2)https://www.cnblogs.com/fengff/p/1101170 ...

  2. MySQL 主从同步延迟的原因及解决办法

    首页 博客 专栏·视频 下载 论坛 问答 代码 直播 能力认证 高校 会员中心 收藏 动态 消息 创作中心 MySQL 主从同步延迟的原因及解决办法 hao_yunfeng 2018-09-04 23 ...

  3. 使用MySQL Proxy解决MySQL主从同步延迟

    MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方 面开发带来了极大的便利.但这种方式有个比较大的缺陷在于MySQL的同步机制是依赖Slave主动向Master发请求来获取数据的, ...

  4. mysql proxy 延迟严重_使用MySQL Proxy解决MySQL主从同步延迟

    MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方面开发带来了极大的便利.但这种方式有个比较大的缺陷在于MySQL的同步机制是依赖Slave主动向Master发请求来获取数据的,而 ...

  5. ntp同步 mysql_解析Mysql 主从同步延迟原理及解决方案

    MySQL的主从同步是一个很成熟的架构,优点为:①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力;②在从主服务器进行备份,避免备份期间影响主服务器服务;③当主服务器出现问题时,可以 ...

  6. js 连mysql 延后_详解MySQL 主从同步延迟

    mysql 用主从同步的方法进行读写分离,减轻主服务器的压力的做法现在在业内做的非常普遍. 主从同步基本上能做到实时同步.我从别的网站借用了主从同步的原理图. 在配置好了, 主从同步以后, 主服务器会 ...

  7. MySQL主从同步延迟原因与解决方案

    一.MySQL数据库主从同步延迟产生的原因 MySQL的主从复制都是单线程的操作,主库对所有DDL和DML产生的日志写进binlog,由于binlog是顺序写,所以效率很高.Slave的SQL Thr ...

  8. Mysql主从同步延迟问题及解决方案

    主从同步出现的延迟问题原因及解决方案 对于主从正常执行,相应的延迟几乎是不存在的.但是在高QPS下,主从同步却出现了比较明显的延迟情况. _______________________________ ...

  9. mysql主从同步延迟优化大全

    mysql> create database fafa; Query OK, 1 row affected (0.01 sec) mysql> use fafa Database chan ...

最新文章

  1. python 画云图_【词云图】如何用python的第三方库jieba和wordcloud画词云图
  2. C++ Primer 5th笔记(chap 16 模板和泛型编程)可变参数模板举例
  3. 分析Oracle有时会用索引来查找数据的原因-oracle执行计划
  4. 腾讯四位创始人向深圳大学捐3.5亿元:启动人才基金
  5. Pytest全局用例共用之conftest.py详解
  6. linux系统电源时钟,linux电源管理的一些梳理
  7. 特斯拉AI Day首秀:FSD终极进化?AI超算Dojo、D1芯片、人形机器人亮相!
  8. Git学习总结(3)——代码托管平台简介
  9. TensorFlow使用--MNIST分类学习(BP神经网络)
  10. [Android]使用Dagger 2依赖注入 - 自定义Scope(翻译)
  11. java程序员面试题大全含答案(2018--2019)
  12. zoom怎么解除静音_Zoom参会者入会后的注意事项
  13. Sublime Text3 插件 拾色器
  14. verilog 中的 log2
  15. 暴力解决个localhost跨域问题
  16. html给页面加背景特效怎么加,给网页加上js特效
  17. 【强化学习】什么是强化学习算法?
  18. iOS微信实现第三方登录的方法
  19. 散列表及散列冲突解决方案
  20. 《 Kubebuilder v2 使用指南 》-P6-CRD Admission Webhook

热门文章

  1. 笨方法学python3 mobi_[下载]Learn Python 3 the Hard Way(已更新完整版PDF\AZW3\EPUB\MOBI)...
  2. android 微信支付测试,求大神指导一下!!!android开发,测试demo按步骤配置,无法调用到微信支付...
  3. java多重继承和多继承_Java不支持多重继承,但可以通过 类实现多继承。类的继承具有 性。 (10.0分)_学小易找答案...
  4. mysql添加标签_PHP / MySQL - 如何添加多个标签
  5. ant 中用到的各种变量的方式
  6. 隐藏右侧“快速启动栏”中的回收站图标及查看所有网站内容
  7. 类库如何读取配置文件(app.config)?
  8. LeetCode 5367. 最长快乐前缀
  9. 安徽省2018计算机一级9月报名,2018年9月份全国计算机等级考试安徽财经大学考点报名通知...
  10. linux amd64目录,解决ubuntu amd64 14.04 bash./ 没有那个文件或目录 的方法(含ia32-libs包的安装方法)...