MySQL压测--异步与半同步复制

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:   最近在看MySQL5.7 Manual,有关Semisynchronous Replication这一块的内容,我们知道,MySQL默认的Replication是异步的,何为异步?何为半同步?废话不多说,直接看官方解释吧:1.

  最近在看MySQL5.7 Manual,有关Semisynchronous Replication这一块的内容,我们知道,MySQL默认的Replication是异步的,何为异步?何为半同步?废话不多说,直接看官方解释吧:


1.背景知识


Asynchronous replication 

the master writes events to its binary log and slaves request them when they are ready. There is no guarantee that any event will ever reach any slave.

--主库只管把events写入binlog中,不管从库有没有收到。


Fully synchronous replication 

when a master commits a transaction, all slaves also will have committed the transaction before the master returns to the session that performed the transaction. The drawback of this is that there might be a lot of delay to complete a transaction.

--主库提交一个事物,需要等待所有从库先提交才能返回结果,执行这个事物。这样会造成一个事物延时。


Semisynchronous replication 

falls between asynchronous and fully synchronous replication. The master waits only until at least one slave has received and logged the events. It does not wait for all slaves to acknowledge receipt, and it requires only receipt, not that the events have been fully executed and committed on the slave side.

--介于异步复制和全复制之间,主库仅仅只要等待至少一个从库收到和记录events。它不需要等待所有的从库告诉它收到events,也不需要从库执行和提交事物,从库只是收到events就会告诉主库,这样主库就可以提前提交事物了。



此外,半同步也分两种,有参数rpl_semi_sync_master_wait_point控制,这里我就不多做解释了,我们使用默认设置after_sync,这种数据零丢失

AFTER_SYNC (the default): The master writes each transaction to its binary log and the slave, and syncs the binary log to disk. The master waits for slave acknowledgment of transaction receipt after the sync. Upon receiving acknowledgment, the master commits the transaction to the storage engine and returns a result to the client, which then can proceed.


AFTER_COMMIT: The master writes each transaction to its binary log and the slave, syncs the binary log, and commits the transaction to the storage engine. The master waits for slave acknowledgment of transaction receipt after the commit. Upon receiving acknowledgment, the master returns a result to the client, which then can proceed.


2.测试环境


Role Hostname IP CPU Memory MySQL Version
TPCC sht-sgmhadoopcm-01 172.16.101.54 2Core 8G NO
master sht-sgmhadoopdn-01 172.16.101.58 2Core 6G 5.7.21
slave1 sht-sgmhadoopdn-02 172.16.101.59 2Core 6G 5.7.21
slave2 sht-sgmhadoopdn-03 172.16.101.60 2Core 6G 5.7.21


一个master,slave1和slave2都是master的直接从库。

分两种情况测试:

(1)当slave1和slave2都是异步复制的时候

(2)当slave1是半同步复制,slave2是异步复制的时候


3.压力测试


使用TPCC压力测试软件,比较TPS判断异步和半同步复制的性能差异到底有多大。

具体如何测试,可以参考之前的博客:MySQL压测--TPCC安装,测试


  • 通过TPCC测试获得的数据库TpmC数据

Thread Count Asynchronous Semisynchronous
4 1145.900 1081.133
8 1966.633 1687.933
16 3202.333 2538.233
32 4363.533 3302.167
64 5112.900 3638.667
128 5257.267 3738.100
256 5199.733 3823.833
512 4753.700 3538.633
1024 3268.633 2769.667
1536 2294.000 2215.733


  • 绘制折线图像

blob.png

4.总结


从本测试结果可以看出:

  • 无论是半同步复制还是异步复制,数据库的TpmC刚开始随着并发线程的增加而增加,到达200个左右,TpmC开始逐渐下降;

  • 当线程数在16-1024左右之间,异步复制的TpmC明显比半同步的大很多,相差大概1000-2000左右,所以半同步相比异步性能是要下降很多;

  • 如果你的数据库并发并不是很多,又对数据安全要求比较高,可以优先考虑使用半同步复制;



参考链接:

半同步复制安装配置

https://dev.mysql.com/doc/refman/5.7/en/replication-semisync.html


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
关系型数据库 MySQL Java
【JMeter】(3)---MySQL压测
【JMeter】(3)---MySQL压测
174 0
|
3月前
|
NoSQL Java 关系型数据库
使用Kafka实现Java异步更新通知解决Redis与MySQL数据不一致
使用Kafka实现Java异步更新通知解决Redis与MySQL数据不一致
41 0
|
9月前
|
消息中间件 canal 缓存
Redis与MySQL双写一致性如何保证:延迟双删?binlog异步删除?
Redis与MySQL双写一致性如何保证:延迟双删?binlog异步删除?
|
4月前
|
关系型数据库 MySQL Serverless
|
5月前
|
关系型数据库 MySQL
MySQL 5.7 基于GTID主从复制+并行复制+半同步复制
MySQL 5.7 基于GTID主从复制+并行复制+半同步复制
75 0
|
SQL 缓存 关系型数据库
MySQL的延迟复制和异步复制的区别是什么?底层原理是什么?
MySQL的延迟复制和异步复制的区别是什么?底层原理是什么?
|
关系型数据库 MySQL 数据库
MySQL的延迟复制、半同步复制,主主复制,异步复制有什么区别?底层原理是什么?
MySQL的延迟复制、半同步复制,主主复制,异步复制有什么区别?底层原理是什么?
252 0
|
存储 关系型数据库 MySQL
MySQL的异步复制是什么意思?底层原理是什么?
MySQL的异步复制是什么意思?底层原理是什么?
|
关系型数据库 MySQL 数据挖掘
MySQL的异步复制是什么意思?底层原理是什么?
MySQL的异步复制是什么意思?底层原理是什么?
140 0
|
关系型数据库 MySQL
MySQL的半同步复制是什么意思?底层原理是什么?
MySQL的半同步复制是什么意思?底层原理是什么?
118 0