Completely resolve the latency issue with MySQL 5.7 Master-slave replication

Source: Internet
Author: User

1. Problem finding
Sysbench test MySQL with the following configuration

sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=192.168.1.221 --mysql-port=3306 --mysql-user=root --mysql-password=MySQL5.7 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=10000 --threads=50 --time=60 --db-driver=mysql --report-interval=10 run >sysbench.log

Check the status of slave after a period of time to find delay severity
Mysql> Show Slave Status\g

...Seconds_Behind_Master: 467...

2. Cause analysis
A server open n links to the client to connect, so there will be large concurrent update operations, but from the inside of the server read Binlog only one, when a SQL to execute from the server for a little longer or because of a SQL to be locked table will lead to the main server SQL backlog, is not synchronized to the slave server. This leads to the inconsistency of the Lord, which is the master-slave delay.

3. Workaround, turn on MySQL 5.7 new feature replication multithreading

mysql> show variables like ‘slave_parallel%‘;+------------------------+----------+| Variable_name          | Value    |+------------------------+----------+| slave_parallel_type    | DATABASE || slave_parallel_workers | 0        |+------------------------+----------+mysql> set global slave_parallel_type=‘logical_clock‘;mysql> set global slave_parallel_workers=100;   #大小根据需要设置mysql> start slave;mysql> show processlist;

4, after a period of time to check the status, has returned to normal

mysql> show slave status\G...Seconds_Behind_Master: 0...

Reference Document: Master-slave replication latency solution under MySQL 5.7

Completely resolve the latency issue with MySQL 5.7 Master-slave replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.