当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
Redis
In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]
技术分析模式(八)双顶和底
Source code analysis of Nacos configuration service (full)
typescript59-泛型工具类型(partial )
17-VMware Horizon 2203 虚拟桌面-Win10 手动桌面池浮动(十七)
FPGA parsing B code----serial 4
Takeda Fiscal 2022 First Quarter Results Strong; On Track to Achieve Full-Year Management Guidance
MySQL表操作练习
技术分析模式(九)三重顶部和底部
360度反馈调查表中的问题示范
【2022 DSCTF决赛wp】
不太会讲爱,其实已经偷偷幸福很久啦----我们的故事
typescript63-索引签名类型
女生做软件测试会不会成为一个趋势?
typescript67-索引查询类型
文本样式这一篇文章就够了
After docker is deployed, mysql cannot connect
微信小程序仿input组件、虚拟键盘
Technical Analysis Mode (8) Double Top and Bottom