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. C++学习之虚函数继承和虚继承

    虚函数的定义要遵循以下重要规则: 1.如果虚函数在基类与派生类中出现,仅仅是名字相同,而形式参数不同,或者是返回类型不同,那么即使加上了virtual关键字,也是不会进行晚绑定的. 2.只有类的成员函 ...

  2. jQuery实现网页右下角悬浮层提示

    最近有同事提到类似网页右下角的消息悬浮提示框的制作.我之前也做过一个类似的例子,很简单.是仿QQ消息.现在感觉之前的那个例子只是说了实现原理,整体上给你的感觉还是太丑,今天为大家带来一个新的例子.是D ...

  3. Poj(2225),三维BFS

    题目链接:http://poj.org/problem?id=2225 这里要注意的是,输入的是坐标x,y,z,那么这个点就是在y行,x列,z层上. 我竟然WA在了结束搜索上了,写成了输出s.step ...

  4. 最终类object 和内部类

    Object 类 性质:[1]是所有类的根类.             [2]如果一个类没有显示继承另外一个类,那么该类一定继承于Object toString() 返回对象的字符串表示形式 特殊:[ ...

  5. 【转】Android开发学习笔记(一)——初识Android

    对于一名程序员来说,“自顶向下”虽然是一种最普通不过的分析问题和解决问题的方式,但其却是简单且较为有效的一种.所以,将其应用到Android的学习中来,不至于将自己的冲动演变为一种盲目和不知所措. 根 ...

  6. 2018.7.8 xmlhttp.readyState==4 && xmlhttp.status==200是什么意思

    在做DOM模型的XML实验的时候遇到了问题 代码实例: xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && ...

  7. 怎么让Sublime Text不自动打开最近的文件/项目

    "hot_exit": false,"remember_open_files": false,

  8. ceph-文件存储

    文件存储 ceph文件系统提供了任何大小的符合posix标准的分布式文件系统,它使用Ceph RADOS存储数据.要实现ceph文件系统,需要一个正在运行的ceph存储集群和至少一个ceph元数据服务 ...

  9. kubernetes-身份与权限认证(十四)

    Kubernetes的安全框架 https://kubernetes.io/docs/reference/access-authn-authz/rbac/ •访问K8S集群的资源需要过三关:认证.鉴权 ...

  10. javaweb基础(36)_jdbc进行批处理

    在实际的项目开发中,有时候需要向数据库发送一批SQL语句执行,这时应避免向数据库一条条的发送执行,而应采用JDBC的批处理机制,以提升执行效率. JDBC实现批处理有两种方式:statement和pr ...