Preface
 
    Semi-synchronous replication is supported since MySQL 5.5 and then enhanced gradually in 5.6 & 5.7.It's also called enhanced semi-synchronous replicaiton in MySQL 5.7.The new method of ACK rule in 5.7(after_sync) make the consistency be strongly guaranteed.Maybe that is the reason why it gets the name.Today I'm gonna demonstrate the effect of sevaral variables of semi-sync.
 
Introduce
 
    Semi-synchronized replicatin can be installed as a plugin.There're a lot of variables with prefix of "repl_semi_sync" after you install the "rpl_semi_sync_master" plugin on your MySQL server.Meanwhile,there're a series of global status about it as well.Let's see the details about it.
 
Framework
Hostname IP/Port Identity OS Version MySQL Version GTID Mode Binlog Format Semi-Sync status
zlm2 192.168.1.101/3306 master CentOS 7.0 5.7.21 on row on
zlm3 192.168.1.102/3306 slave1 CentOS 7.0 5.7.21 on row on
zlm4 192.168.1.103/3306 slave2 CentOS 7.0 5.7.21 on row on
 
Example
 
Check the variables relevant to semi-sync replication.
 //Master
(zlm@192.168.1.101 )[(none)]>show variables like 'rpl_semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | OFF |
| rpl_semi_sync_master_timeout | |
| rpl_semi_sync_master_trace_level | |
| rpl_semi_sync_master_wait_for_slave_count | |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
+-------------------------------------------+------------+
rows in set (0.00 sec) //rpl_semi_sync_master_enabled --Specify whether to use the feature of semi-sync(master side,default "off").
//rpl_semi_sync_master_timeout --Specify the threshold of timeout between master and slave(default value is "10000" means 10s).
//rpl_semi_sync_master_trace_level --Specify the debug trace level on master(default "32",others "1","16","64").
//rpl_semi_sync_master_wait_for_slave_count --Specify how many slaves the master should wait when timeout happens(default "1").
//rpl_semi_sync_master_wait_no_slave --Specify whether the master switches to normal replication(default "on").When setting "on",it permits the amount of slave can be less than the value of "rpl_semi_sync_master_wait_for_slave_count" you specified and prevents it becoming normal replication.
//rpl_semi_sync_master_wait_point --Specify the ACK mode(default "after-sync").It's the most important variable of semi-sync. //Slave1
(zlm@192.168.1.102 )[(none)]>show variables like 'rpl_semi%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled | OFF |
| rpl_semi_sync_slave_trace_level | |
+---------------------------------+-------+
rows in set (0.00 sec) //There're only two variables after install the rpl_semi_sync_slave plugin.
//rpl_semi_sync_slave_enabled -- Specify whether use the feature of semi-sync(slave side,default "off").
//rpl_semi_sync_slave_trace_level -- Specify the debug trace level on slave(default "32").
Enable semi-sync replication on both master and slaves.
 //Master
(zlm@192.168.1.101 )[(none)]>set rpl_semi_sync_master_enabled=on;
ERROR (HY000): Variable 'rpl_semi_sync_master_enabled' is a GLOBAL variable and should be set with SET GLOBAL
(zlm@192.168.1.101 )[(none)]>set global rpl_semi_sync_master_enabled=on;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.101 )[(none)]>show variables like 'rpl_semi_sync_master_enabled';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| rpl_semi_sync_master_enabled | ON |
+------------------------------+-------+
row in set (0.01 sec) //Slave1
(zlm@192.168.1.102 )[(none)]>set @@global.rpl_semi_sync_slave_enabled=on;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.102 )[(none)]>show variables like 'rpl_semi_sync%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | |
+---------------------------------+-------+
rows in set (0.00 sec) //Slave2
(zlm@192.168.1.103 )[(none)]>set @@global.rpl_semi_sync_slave_enabled=on;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.103 )[(none)]>show variables like 'rpl_semi_sync%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | |
+---------------------------------+-------+
rows in set (0.01 sec) //Master
(zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync_master_clients';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| Rpl_semi_sync_master_clients | | //It means there're two slaves using semi-sync replicaiton follow master now.
+------------------------------+-------+
row in set (0.00 sec)
Execute sysbench to generate some trasactions.
 [root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_insert.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --tables= --table-size= --mysql-storage-engine=innodb prepare
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Creating table 'sbtest1'...
Inserting records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting records into 'sbtest5'
Creating a secondary index on 'sbtest5'... [root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_insert.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --threads= --time= --report-interval= --rand-type=uniform run
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Running the test with following options:
Number of threads:
Report intermediate results every second(s)
Initializing random number generator from current time Initializing worker threads... Threads started! [ 30s ] thds: tps: 931.95 qps: 931.95 (r/w/o: 0.00/931.95/0.00) lat (ms,%): 6.09 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: tps: 971.62 qps: 971.62 (r/w/o: 0.00/971.62/0.00) lat (ms,%): 5.18 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: tps: 949.33 qps: 949.33 (r/w/o: 0.00/949.33/0.00) lat (ms,%): 4.41 err/s: 0.00 reconn/s: 0.00
Check the global status of semi-sync on master.
 (zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync%';
+--------------------------------------------+------------+
| Variable_name | Value |
+--------------------------------------------+------------+
| Rpl_semi_sync_master_clients | |
| Rpl_semi_sync_master_net_avg_wait_time | |
| Rpl_semi_sync_master_net_wait_time | |
| Rpl_semi_sync_master_net_waits | |
| Rpl_semi_sync_master_no_times | |
| Rpl_semi_sync_master_no_tx | |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | |
| Rpl_semi_sync_master_tx_avg_wait_time | |
| Rpl_semi_sync_master_tx_wait_time | |
| Rpl_semi_sync_master_tx_waits | |
| Rpl_semi_sync_master_wait_pos_backtraverse | |
| Rpl_semi_sync_master_wait_sessions | |
| Rpl_semi_sync_master_yes_tx | |
+--------------------------------------------+------------+
rows in set (0.00 sec)
Set the variable "rpl_semi_sync_master_timeout" to 60000.
 (zlm@192.168.1.101 )[(none)]>set @@global.rpl_semi_sync_master_timeout=;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.101 )[(none)]>show global variables like 'rpl_semi_sync_master_timeout';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| rpl_semi_sync_master_timeout | |
+------------------------------+-------+
row in set (0.00 sec)
Stop slave on slave1 and record the execution time.
 (zlm@192.168.1.102 )[(none)]>system date
Mon Jul :: CEST
(zlm@192.168.1.102 )[(none)]>stop slave; //The stopping time was 11:20:40 around.
Query OK, rows affected (0.84 sec)
Check the global status of semi-sync and error log on master.
 (zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync%';
+--------------------------------------------+------------+
| Variable_name | Value |
+--------------------------------------------+------------+
| Rpl_semi_sync_master_clients | | //The amount of client turned into "1".
| Rpl_semi_sync_master_net_avg_wait_time | |
| Rpl_semi_sync_master_net_wait_time | |
| Rpl_semi_sync_master_net_waits | |
| Rpl_semi_sync_master_no_times | |
| Rpl_semi_sync_master_no_tx | |
| Rpl_semi_sync_master_status | ON | //Although the amount of client has been less than "slave_count" but it still work in semi-sync mode.
| Rpl_semi_sync_master_timefunc_failures | |
| Rpl_semi_sync_master_tx_avg_wait_time | |
| Rpl_semi_sync_master_tx_wait_time | |
| Rpl_semi_sync_master_tx_waits | |
| Rpl_semi_sync_master_wait_pos_backtraverse | |
| Rpl_semi_sync_master_wait_sessions | |
| Rpl_semi_sync_master_yes_tx | |
+--------------------------------------------+------------+
rows in set (0.00 sec) --16T11::39.628398+: [ERROR] mysqld: Got an error reading communication packets //It's the time I stopped the slave on slave1.
--16T11::40.355498+: [ERROR] Semi-sync master failed on net_flush() before waiting for slave reply
--16T11::40.355532+: [Note] Stop semi-sync binlog_dump to slave (server_id: )
--16T11::41.358003+: [Note] Aborted connection to db: 'unconnected' user: 'repl' host: 'zlm3' (Found net error)
--16T11::43.367327+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 6128ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::59.683904+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 15315ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::05.709621+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 5025ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::40.353597+: [Warning] Timeout waiting for reply of binlog (file: mysql-bin., pos: ), semi-sync up to file mysql-bin., position .
--16T11::40.353630+: [Note] Semi-sync replication switched OFF. //Until the timeout was accumulated to 60s(11:21:40),the semi-sync mode reverts "OFF" what means the master work as asynchronous replication. (zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync%';
+--------------------------------------------+------------+
| Variable_name | Value |
+--------------------------------------------+------------+
| Rpl_semi_sync_master_clients | |
| Rpl_semi_sync_master_net_avg_wait_time | |
| Rpl_semi_sync_master_net_wait_time | |
| Rpl_semi_sync_master_net_waits | |
| Rpl_semi_sync_master_no_times | |
| Rpl_semi_sync_master_no_tx | |
| Rpl_semi_sync_master_status | OFF | //Now the status became "OFF".
| Rpl_semi_sync_master_timefunc_failures | |
| Rpl_semi_sync_master_tx_avg_wait_time | |
| Rpl_semi_sync_master_tx_wait_time | |
| Rpl_semi_sync_master_tx_waits | |
| Rpl_semi_sync_master_wait_pos_backtraverse | |
| Rpl_semi_sync_master_wait_sessions | |
| Rpl_semi_sync_master_yes_tx | |
+--------------------------------------------+------------+
rows in set (0.00 sec)
Change the variable "rpl_semi_sync_master_wait_no_slave" ot off.
 (zlm@192.168.1.101 )[(none)]>set @@global.rpl_semi_sync_master_wait_no_slave=off;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.101 )[(none)]>show global variables like 'rpl_semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | |
| rpl_semi_sync_master_trace_level | |
| rpl_semi_sync_master_wait_for_slave_count | |
| rpl_semi_sync_master_wait_no_slave | OFF |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
+-------------------------------------------+------------+
rows in set (0.00 sec)
Start slave on slave1 to restore the initial status of semi-sync replication.
 //Slave
(zlm@192.168.1.102 )[(none)]>start slave;
Query OK, rows affected (0.01 sec) //Error log of master
--16T11::22.727473+: [Note] Start binlog_dump to master_thread_id() slave_server(), pos(, )
--16T11::31.005135+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 8431ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::31.838932+: [Note] Start semi-sync binlog_dump to slave (server_id: ), pos(, )
--16T11::50.117239+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 6667ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::59.977585+: [Note] Semi-sync replication switched ON at (mysql-bin., )
Stop slave on slave1 again and record the execution time.
 (zlm@192.168.1.102 )[(none)]>system date
Mon Jul :: CEST
(zlm@192.168.1.102 )[(none)]>stop slave; //The stopping time was 11:35:58 around.
Query OK, rows affected (1.60 sec)
Check the global status of semi-sync and error log on master one more time. 
 (zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync%';
+--------------------------------------------+------------+
| Variable_name | Value |
+--------------------------------------------+------------+
| Rpl_semi_sync_master_clients | |
| Rpl_semi_sync_master_net_avg_wait_time | |
| Rpl_semi_sync_master_net_wait_time | |
| Rpl_semi_sync_master_net_waits | |
| Rpl_semi_sync_master_no_times | |
| Rpl_semi_sync_master_no_tx | |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | |
| Rpl_semi_sync_master_tx_avg_wait_time | |
| Rpl_semi_sync_master_tx_wait_time | |
| Rpl_semi_sync_master_tx_waits | |
| Rpl_semi_sync_master_wait_pos_backtraverse | |
| Rpl_semi_sync_master_wait_sessions | |
| Rpl_semi_sync_master_yes_tx | |
+--------------------------------------------+------------+
rows in set (0.00 sec) --16T11::58.920988+: [ERROR] mysqld: Got an error reading communication packets
--16T11::00.321218+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 14988ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::11.150976+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 8718ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--16T11::28.973672+: [Note] Stop semi-sync binlog_dump to slave (server_id: )
--16T11::29.012288+: [Note] Semi-sync replication switched OFF. //The master didn't wait the timeout occur and revert to aynchronous replication directly within about merely 30s. (zlm@192.168.1.101 )[(none)]>show global status like 'Rpl_semi_sync%';
+--------------------------------------------+------------+
| Variable_name | Value |
+--------------------------------------------+------------+
| Rpl_semi_sync_master_clients | |
| Rpl_semi_sync_master_net_avg_wait_time | |
| Rpl_semi_sync_master_net_wait_time | |
| Rpl_semi_sync_master_net_waits | |
| Rpl_semi_sync_master_no_times | |
| Rpl_semi_sync_master_no_tx | |
| Rpl_semi_sync_master_status | OFF |
| Rpl_semi_sync_master_timefunc_failures | |
| Rpl_semi_sync_master_tx_avg_wait_time | |
| Rpl_semi_sync_master_tx_wait_time | |
| Rpl_semi_sync_master_tx_waits | |
| Rpl_semi_sync_master_wait_pos_backtraverse | |
| Rpl_semi_sync_master_wait_sessions | |
| Rpl_semi_sync_master_yes_tx | |
+--------------------------------------------+------------+
rows in set (0.00 sec)
Summay
  • The behavior of semi-sync replication depends on the variables that you specified.
  • If the value of "rpl_semi_sync_master_wait_no_slave" is "on",the status of semi-sync won't change until it reaches the value of timeout,even though the amount of slaves are less than it in "rpl_semi_sync_master_slave_count".
  • If the value of "rpl_semi_sync_master_wait_no_slave" is "off",master won't wait for timeout before it reverts to normal replication when slave decreases to less than the value above.
  • In order to observe the result conveniently,I increase the value of "rpl_semi_sync_master_timeout" to 60s.
  • In most high consistent scenarios,the value can be tremendous enough to avoid degenerating to asynchronous replication.
  • If the degeneration is due to network failure such as instant glitch.The semi-sync status will be ok after the network becomes normal.
  • I'm afraid the best practice is to set "rpl_semi_sync_master_wait_no_slave" to "on" and the "rpl_semi_sync_master_timeout" to a comparative value.

MySQL增强半同步几个重要参数搭配的测试的更多相关文章

  1. Bullet:MySQL增强半同步参数rpl_semi_sync_master_wait_point值AFTER_SYNC和AFTER_COMMIT的对比实验

    MySQL 5.7.22启用增强半同步复制 MySQL对该参数值的描述 Semisync can wait for slave ACKs at one of two points, AFTER_SYN ...

  2. MySQL增强半同步的搭建实验,和一些参数的个人理解

    关于参数理解,已补充实验,可以查看: rpl_semi_sync_master_wait_no_slave 参数研究实验 环境信息 role ip port hostname master 192.1 ...

  3. MySQL 5.7的复制架构,在有异步复制、半同步、增强半同步、MGR等的生产中,该如何选择?

    一.生产环境中: 几种复制场景都有存在的价值.下面分别描述一下: 从成熟度上来选择,推荐:异步复制(GTID+ROW) 从数据安全及更高性能上选择:增强半同步 (在这个结构下也可以把innodb_fl ...

  4. (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现

           架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用        优势:       ...

  5. PostgreSQL的同步级别与MySQL的半同步after_sync比较

    MySQL的半同步中通过binlog进行流复制,同步级别和PostgreSQL对比可以发现: PostgreSQL                MySQL off local            ...

  6. MySQL的半同步是什么?

    前言 年后在进行腾讯二面的时候,写完算法的后问的第一个问题就是,MySQL的半同步是什么?我当时直接懵了,我以为是问的MySQL的两阶段提交的问题呢?结果确认了一下后不是两阶段提交,然后面试官看我连问 ...

  7. mysql的半同步复制

    1. binlog dump线程何时向从库发送binlog mysql在server层进行了组提交之后,为了提高并行度,将提交阶段分为了 flush sync commit三个阶段,根据sync_bi ...

  8. MySQL 5.7 新特性之增强半同步复制

    1. 背景介绍 半同步复制 普通的replication,即mysql的异步复制,依靠mysql二进制日志也即binary log进行数据复制.比如两台机器,一台主机(master),另外一台是从机( ...

  9. MySQL主从复制半同步复制原理及搭建

    在MySQL5.5之前的版本中,MySQL的复制是异步复制,主库和从库的数据之间存在一定的延迟,比如网络故障等各种原因,这样子容易存在隐患就是:当在主库写入一个事务成功后并提交了,但是由于从库延迟没有 ...

随机推荐

  1. Leetcode 22. Generate Parentheses Restore IP Addresses (*) 131. Palindrome Partitioning

    backtracking and invariant during generating the parathese righjt > left  (open bracket and cloas ...

  2. WSL的unable to resolve host问题

    运行apt-get的时候提示 sudo: unable to resolve host DESKTOP-PS8VD9E 在 /etc/hosts文件中 127.0.0.1 对应主机名字给加一行就好了

  3. MYSQL的基本语法

    .默认约束 区别:mysql里面DEFAULT关键字后面是不用加括号的 复制代码 代码如下: --sqlserver CREATE TABLE emp ( id INT DEFAULT() ) --m ...

  4. Codeforces 758A Holiday Of Equality

    题目链接:http://codeforces.com/problemset/problem/758/A A. Holiday Of Equality time limit per test 1 sec ...

  5. 下载Xcode历史版本方法

    1.打开链接:https://developer.apple.com/download/more 进入页面 2.在搜索框输入Xcode,回车搜索.如图,找到各种版本Xcode 搜索Xcode 3.双击 ...

  6. php curl使用总结(一)

    今天和第三方支付做对接的时候,在本地用wamp(php版本5.4.14)运行他们的支付demo的时候,报了一个错误.loadXML函数中不能传空值.排查代码的时候,发现他们用了curl,我以前也接触过 ...

  7. Java后台-面试问题汇总(转载)

    总结这些天面试Java开发过程中的大多数问题,综合分类有Java基础,框架,多线程,网络通信,Linux,数据库,设计模式,算法,缓存等几个模块,由于问题太多,下面先列出问题,之后有时间在写文章解答, ...

  8. Oracle 的jdbc方法

    package com.swift.jdbc_oracle; import java.sql.CallableStatement; import java.sql.Connection; import ...

  9. sqlite3基本操作

    在移动设备上进行高性能高效率的大量数据存储,我们一般用得时sqlite这款轻巧型的数据库,这里介绍其增删改查基本功能 在ios开发中我们需要先导入"libsqlite3.dylib" ...

  10. 1237: [SCOI2008]配对

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1789  Solved: 715[Submit][Status][Discuss] Descripti ...