本文介绍如何通过mysqlsct工具来测试PolarDB MySQL版的全局一致性(高性能模式)功能。
测试工具
开源的mysqlsct工具可用于检验数据库集群的全局一致性(高性能模式)能力,该工具通过跨Session的写入、读取和结果对比的方式来测试数据库全局一致性(高性能模式)功能和性能。
测试环境
-
测试的ECS和PolarDB MySQL版均在同一地域、同一可用区。
-
网络类型均为VPC网络。
说明ECS实例和PolarDB MySQL版需保证在同一个VPC中。
-
测试用的PolarDB MySQL版如下:
-
节点规格为polar.mysql.x8.4xlarge(8核32 GB独享规格)。
-
两节点集群(一主一只读)。
-
使用的连接串为集群地址,如何查看PolarDB MySQL版地址请参见管理连接地址。
-
-
测试用的ECS实例信息如下:
-
实例规格为ecs.g7.2xlarge。
-
实例所使用的镜像为CentOS 7.9 64位。
-
安装mysqlsct
本文档中的命令只能由root权限的用户来执行。
-
在ECS中执行如下命令安装mysqlsct的编译依赖工具。
yum install gcc gcc-c++ cmake3 mariadb-devel.x86_64 -y -
安装git。
yum install git -y -
下载mysqlsct工具代码。
git clone https://github.com/sunashe/mysqlsct.git -
编译mysqlsct工具。
cd mysqlsct cmake3 . make编译完成后会在当前目录下生成可执行的二进制文件
mysqlsct。如下:ll 总用量 176 -rw-r--r-- 1 user user 13821 9月 14 09:57 CMakeCache.txt drwxr-xr-x 5 user user 4096 9月 14 09:57 CMakeFiles -rw-r--r-- 1 user user 1488 9月 14 09:57 cmake_install.cmake -rw-r--r-- 1 user user 300 9月 14 09:56 CMakeLists.txt -rw-r--r-- 1 user user 34523 9月 14 09:56 LICENSE -rw-r--r-- 1 user user 5170 9月 14 09:57 Makefile -rwxr-xr-x 1 user user 78232 9月 14 09:57 mysqlsct #可执行的二进制文件mysqlsct -rw-r--r-- 1 user user 18138 9月 14 09:56 mysqlsct.cc -rw-r--r-- 1 user user 2456 9月 14 09:56 README.md
测试方法
-
设置PolarDB MySQL版集群地址的一致性级别。具体操作请参见配置数据库代理。
对于全局一致性(高性能模式),需要先在控制台上将集群地址的一致性级别设置为最终一致性(弱),然后再开启全局一致性(高性能模式)。
-
在ECS上的
mysqlsct目录下,执行如下命令来进行一致性测试。./mysqlsct --host-rw=pc-**********.rwlb.rds.aliyuncs.com //测试环境中PolarDB MySQL版的集群地址。host-rw与host-ro的集群地址相同。 --host-ro=pc-**********.rwlb.rds.aliyuncs.com //测试环境中PolarDB MySQL版的集群地址。host-ro与host-rw的集群地址相同。 --port-rw=3306 //测试环境中PolarDB MySQL版的集群地址端口 --port-ro=3306 //测试环境中PolarDB MySQL版的集群地址端口 --user=****** //PolarDB MySQL版的集群测试账号 --password=****** //PolarDB MySQL版的集群测试密码 --iterations=1000000 //测试总次数(一次update+一次select为一次测试) --table-cnt=100 //测试表数量 --table-size=1000 //测试表行数 --concurrency=100 //测试并发线程数 --database=sct //测试数据库 --sc-gap-us=0 //update和select之间的休眠时间, 0表示update后立刻发起查询 --report-interval=5 //打印日志间隔 --detail-log=0 //不输出详细错误日志
测试结果
-
最终一致性测试结果
Input parameters: host-rw: xxx.10904.rwlb.rds.aliyuncs.com host-ro: xxx.r10904.rwlb.rds.aliyuncs.com database: sct port-rw: 3306 port-ro: 3306 user: xxx password: xxx iterations: 1000000 table-cnt: 100 table-size: 1000 sc-gap-us: 0 report-interval: 5 detail-log: 0 concurrency: 100 ######################################## Failed to check the table size, sct36 should be: 1000, but 998 Failed to check the table size, sct54 should be: 1000, but 999 Strict consistency tps: 7483, failed tps: 3053 Strict consistency tps: 18578, failed tps: 8225 Strict consistency tps: 18646, failed tps: 8767 Strict consistency tps: 18658, failed tps: 8036 Strict consistency tps: 18793, failed tps: 8146 Strict consistency tps: 18871, failed tps: 8977 ^@Strict consistency tps: 18736, failed tps: 7964 Strict consistency tps: 18692, failed tps: 7957 Strict consistency tps: 18764, failed tps: 9086 Strict consistency tps: 18561, failed tps: 8049 Strict consistency tps: 18959, failed tps: 8478 Strict consistency tps: 5254, failed tps: 2330 Test strict consistency cnt: 1000000, failed cnt: 445368从上方输出中的最终一致性测试结果可以看出,最终一致性并不能保证写后读的数据一致性。
-
会话一致性测试结果
会话一致性测试结果如下所示。
Input parameters: host-rw: xxx.rwlb.rds.aliyuncs.com host-ro: xxx.vlb.rds.aliyuncs.com database: sct port-rw: 3306 port-ro: 3306 user: xxx password: xxx iterations: 1000000 table-cnt: 100 table-size: 1000 sc-gap-us: 0 report-interval: 5 detail-log: 0 concurrency: 100 ######################################## Strict consistency tps: 8013, failed tps: 2646 Strict consistency tps: 18763, failed tps: 8363 Strict consistency tps: 18751, failed tps: 7534 Strict consistency tps: 18777, failed tps: 7857 Strict consistency tps: 18634, failed tps: 7533 Strict consistency tps: 16815, failed tps: 6218 Strict consistency tps: 18681, failed tps: 7604 Strict consistency tps: 18596, failed tps: 7640 Strict consistency tps: 18876, failed tps: 7925 Strict consistency tps: 18713, failed tps: 7740 Strict consistency tps: 18730, failed tps: 8135 Strict consistency tps: 6647, failed tps: 2706 Test strict consistency cnt: 1000000, failed cnt: 409528从上方输出中的会话一致性测试结果可以看出,会话一致性并不能保证跨 Session 的强一致性。
-
全局一致性测试结果
Input parameters: host-rw: xxx.rwlb.rds.aliyuncs.com host-ro: xxx.rwlb.rds.aliyuncs.com database: sct port-rw: 3306 port-ro: 3306 user: xxx password: xxx iterations: 1000000 table-cnt: 100 table-size: 1000 sc-gap-us: 0 report-interval: 5 detail-log: 0 concurrency: 100 ############################################## Strict consistency tps: 4515, failed tps: 0 Strict consistency tps: 9948, failed tps: 0 Strict consistency tps: 10048, failed tps: 0 Strict consistency tps: 10367, failed tps: 0 Strict consistency tps: 9979, failed tps: 0 Strict consistency tps: 10201, failed tps: 0 Strict consistency tps: 10197, failed tps: 0 Strict consistency tps: 9946, failed tps: 0 Strict consistency tps: 9554, failed tps: 0 Strict consistency tps: 10011, failed tps: 0 Strict consistency tps: 9908, failed tps: 0 Strict consistency tps: 9970, failed tps: 0 Strict consistency tps: 10129, failed tps: 0 Strict consistency tps: 9873, failed tps: 0 Strict consistency tps: 9954, failed tps: 0 Strict consistency tps: 9875, failed tps: 0 Strict consistency tps: 9848, failed tps: 0 Strict consistency tps: 9864, failed tps: 0 Strict consistency tps: 10022, failed tps: 0 Strict consistency tps: 10127, failed tps: 0 Strict consistency tps: 5654, failed tps: 0 Test strict consistency cnt: 1000000, failed cnt: 0从上方输出中的全局一致性测试结果可以看出,全局一致性可以保证跨 Session 的强一致性。
-
全局一致性(高性能模式)测试结果
全局一致性(高性能模式)测试结果如下所示,100 万次迭代、并发 100 的场景下失败数为 0,验证全局一致性(高性能模式)可保证跨 Session 的强一致性。
input parameters: host-rw: xxx0904.rwlb.rds.aliyuncs.com host-ro: xxx0904.rwlb.rds.aliyuncs.com database: sct port-rw: 3306 port-ro: 3306 user: xxx password: xxx iterations: 1000000 table-cnt: 100 table-size: 1000 sc-gap-us: 0 report-interval: 5 detail-log: 0 concurrency: 100 ########################################## Strict consistency tps: 5914, failed tps: 0 Strict consistency tps: 15376, failed tps: 0 Strict consistency tps: 15353, failed tps: 0 Strict consistency tps: 15602, failed tps: 0 Strict consistency tps: 15365, failed tps: 0 Strict consistency tps: 15384, failed tps: 0 Strict consistency tps: 15480, failed tps: 0 Strict consistency tps: 15544, failed tps: 0 Strict consistency tps: 15227, failed tps: 0 Strict consistency tps: 12452, failed tps: 0 Strict consistency tps: 15288, failed tps: 0 Strict consistency tps: 15492, failed tps: 0 Strict consistency tps: 15327, failed tps: 0 Strict consistency tps: 12190, failed tps: 0 Test strict consistency cnt: 1000000, failed cnt: 0从上方输出中的全局一致性(高性能模式)测试结果可以看出,全局一致性(高性能模式)可以保证跨 Session 的强一致性。