当前位置:网站首页>Mysql master-slave delay reasons and solutions
Mysql master-slave delay reasons and solutions
2022-08-05 07:03:00 【Eat well without getting fat】
MySQL master-slave replication
First of all, there are two main ways of binlog recording (excluding Mixed)
statement--SBR operation-based SQL statementAdvantages: It is not necessary to record the changes of each SQL statement and each row of data, which reduces the amount of binlog logs, saves I/O, and improves performance.Disadvantage: In some cases, the primary and secondary data are inconsistent.row---RBR based on row changes (data records before and after changes)Advantages: It does not record the context information of each SQL statement, but only records the detailed modification details of the data, which is the safest.Disadvantage: Generates a lot of logs and consumes disk space.The master-slave replication process of MySQL can refer to the following article, which is omitted here.
Master-slave replication process
Master-Slave Delay
At t1, the main library executes the transaction and writes it to the binlogAt time t2, the slave library receives the binlog (IO thread) of the main library and writes to the relay logAt time t3, the SQL thread of the slave library executes the SQL statement to complete the transactionThe master-slave delay means that the time difference between the completion of the execution of the slave library and the completion of the execution of the main library is greater than (t3-t1)Possible causes and solutions for master-slave delay
1) Hardware differences between master and slave servers.The performance of the slave database machine is poor, and the data of the master database cannot be synchronized in time. It is only necessary to replace the new device or keep the same device.
2) The reading pressure from the library is high.Generally, the main library "writes" and the slave library "reads".A large number of "read" requests hitting the slave library will consume a lot of system resources of the slave library, thereby affecting the synchronization speed of the slave library.At this time, a master-multiple-slave architecture can be built to share the pressure of "read" requests.
3) Big business.If the transaction is executed in the master database for 15 minutes, the synchronization in the slave database will also take at least 15 minutes, resulting in master-slave delay.Transactions are done in batches if possible.
4) Network latency.The network communication status will also affect the master-slave replication (affecting the IO thread of the slave library to obtain the master library binlog), only the bandwidth can be upgraded and the network can be optimized.
5) Too many libraries.Generally, 3-5 slave nodes are the best.
边栏推荐
猜你喜欢
随机推荐
概率与期望部分题解
The NDK compiler so libraries
八大排序之快速排序
typescript62-泛型工具类型(record)
【2022 DSCTF决赛wp】
【内推】新相微电子
【FAQ】What is Canon CCAPI
2022杭电多校六 1006-Maex (树形DP)
边缘盒子+时序数据库,美的数字化平台 iBUILDING 背后的技术选型
【MyCat简单介绍】
字节面试流程及面试题无私奉献,吐血整理
ndk编译so库
腾讯实习总结
In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]
【工具配置篇】VSCode 常用使用总结
TCP的粘包拆包问题+解决方案
淘宝客APP带自营商城本地生活CPS外卖优惠电影票话费更新渠道跟单生活特权V3
淘宝宝贝页面制作
360度反馈调查表中的问题示范
typescript65-映射类型(keyof)









