本文介绍如何使用TPC-C工具测试PolarDB-X(引擎版本MySQL 5.7和MySQL 8.0)数据库的联机交易处理(偏向OLTP能力),您可以按照本文的介绍自行测试进行对比,快速了解数据库系统的性能。
背景信息
TPC-C是业界常用的一套Benchmark,由TPC委员会制定发布,用于评测数据库的联机交易处理(偏向OLTP)能力。主要涉及10张表,包含了NewOrder(新订单的生成)、Payment(订单付款)、OrderStatus(最近订单查询)、Delivery(配送)和StockLevel(库存缺货状态分析)等五类业务事务模型。TPC-C使用tpmC值(Transactions per Minute)来衡量系统最大有效吞吐量(MQTh,Max Qualified Throughput),其中Transactions以NewOrder Transaction为准,即最终衡量单位为每分钟处理的新订单数。
本文中TPC-C的实现基于TPC-C的基准测试,并不能与已发布的TPC-C基准测试结果相比较,本文中的测试并不符合TPC-C基准测试的所有要求。
测试设计
测试数据量
基于1000 Warehouse,其中主要表的数据量如下:
bmsql_order_line表3亿行
bmsql_stock表1亿行
bmsql_customer、bmsql_history、bmsql_order各3000万行
测试所用实例规格
节点规格
节点数
4C32G
2
4C32G
4
8C64G
2
8C64G
4
测试所用压力机规格
ecs.g6.8xlarge(32 vCPU,128 GB内存)
测试方法
准备压力机ECS
准备一个ECS(建议配置为32 vCPU 128 GB内存,避免在测试高规格集群时,压力机成为瓶颈),后续操作步骤中涉及的数据准备、运行压测等使用的都是这台ECS机器。
说明测试所用ECS需要部署在VPC网络内。请记录该VPC的名称和ID,后续的所有实例都将部署在该VPC内。
准备压测所用PolarDB-X实例
创建PolarDB-X实例(按需选择引擎版本MySQL 5.7或MySQL 8.0),详细操作步骤请参见创建实例。
在实例中创建一个待压测的数据库(本测试中数据库名为tpcc_1000),详细操作步骤请参见创建数据库。
CREATE DATABASE tpcc_1000;
说明需保证ECS和PolarDB-X实例在同一个VPC中。
调整实例参数
说明为了在压测场景下达到最佳性能,需要调整部分PolarDB-X计算层实例参数。
修改参数ENABLE_COROUTINE的值为true,XPROTO_MAX_DN_CONCURRENT和XPROTO_MAX_DN_WAIT_CONNECTION的值为4000,详细操作步骤请参见参数设置。
通过命令行连接到PolarDB-X实例,在同一会话内执行如下SQL语句,关闭日志记录与CPU采样统计:
set global RECORD_SQL=false; set global MPP_METRIC_LEVEL=0; set global ENABLE_CPU_PROFILE=false; set global ENABLE_TRANS_LOG=false;
准备压测数据
准备压测工具
说明BenchmarkSQL默认不支持MySQL协议,需要进行工具改造适配(此处提供了基于开源BenchmarkSQL 5.0改动后的源码以及编译后的jar包)。
下载压测工具包benchmarksql.tar.gz并上传至压力机ECS上,执行以下命令进行解压:
tar xzvf benchmarksql.tar.gz
压测配置
在ECS上执行如下命令,修改props.mysql配置文件,并填入对应的PolarDB-X实例连接信息:
cd benchmarksql/run vi props.mysql
其中, 配置文件以及主要参数解释如下:
db=mysql driver=com.mysql.jdbc.Driver conn=jdbc:mysql://{HOST}:{PORT}/tpcc?readOnlyPropagatesToServer=false&rewriteBatchedStatements=true&failOverReadOnly=false&connectTimeout=3000&socketTimeout=90000&allowMultiQueries=true&clobberStreamingResults=true&characterEncoding=utf8&netTimeoutForStreamingResults=0&autoReconnect=true user={USER} password={PASSWORD} warehouses=1000 loadWorkers=100 terminals=128 //To run specified transactions per terminal- runMins must equal zero runTxnsPerTerminal=0 //To run for specified minutes- runTxnsPerTerminal must equal zero runMins=5 //Number of total transactions per minute limitTxnsPerMin=0 //Set to true to run in 4.x compatible mode. Set to false to use the //entire configured database evenly. terminalWarehouseFixed=true //The following five values must add up to 100 //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec newOrderWeight=45 paymentWeight=43 orderStatusWeight=4 deliveryWeight=4 stockLevelWeight=4 // Directory name to create for collecting detailed result data. // Comment this out to suppress. resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS // osCollectorScript=./misc/os_collector_linux.py // osCollectorInterval=1 // osCollectorSSHAddr=user@dbhost // osCollectorDevices=net_eth0 blk_sda
conn:连接串配置,需填入主机名{HOST}、端口号{PORT}
user:用户名
password:密码
warehouses:仓库数
loadWorkers:导入数据并发数
terminals:压测并发数
runMins:压测时间
导入压测数据
在压力机ECS中执行如下命令导入压测数据:
cd benchmarksql/run/sql.common cp tableCreates.sql.auto tableCreates.sql cd .. nohup ./runDatabaseBuild.sh props.mysql &
说明默认按照100并发导入,总共5亿多条记录,整体导入时间在小时级别,建议通过nohup推到后台运行,避免ssh命令行断开导致导入中断。
验证数据完整性
通过命令行连接到PolarDB-X实例执行以下SQL,若返回结果集均为空,证明数据完整。
select a.* from (Select w_id, w_ytd from bmsql_warehouse) a left join (select d_w_id, sum(d_ytd) as d_ytd_sum from bmsql_district group by d_w_id) b on a.w_id = b.d_w_id and a.w_ytd = b.d_ytd_sum where b.d_w_id is null; select a.* from (Select d_w_id, d_id, D_NEXT_O_ID - 1 as d_n_o_id from bmsql_district) a left join (select o_w_id, o_d_id, max(o_id) as o_id_max from bmsql_oorder group by o_w_id, o_d_id) b on a.d_w_id = b.o_w_id and a.d_id = b.o_d_id and a.d_n_o_id = b.o_id_max where b.o_w_id is null; select a.* from (Select d_w_id, d_id, D_NEXT_O_ID - 1 as d_n_o_id from bmsql_district) a left join (select no_w_id, no_d_id, max(no_o_id) as no_id_max from bmsql_new_order group by no_w_id, no_d_id) b on a.d_w_id = b.no_w_id and a.d_id = b.no_d_id and a.d_n_o_id = b.no_id_max where b.no_id_max is null; select * from (select (count(no_o_id)-(max(no_o_id)-min(no_o_id)+1)) as diff from bmsql_new_order group by no_w_id, no_d_id) a where diff != 0; select a.* from (select o_w_id, o_d_id, sum(o_ol_cnt) as o_ol_cnt_cnt from bmsql_oorder group by o_w_id, o_d_id) a left join (select ol_w_id, ol_d_id, count(ol_o_id) as ol_o_id_cnt from bmsql_order_line group by ol_w_id, ol_d_id) b on a.o_w_id = b.ol_w_id and a.o_d_id = b.ol_d_id and a.o_ol_cnt_cnt = b.ol_o_id_cnt where b.ol_w_id is null; select a.* from (select d_w_id, sum(d_ytd) as d_ytd_sum from bmsql_district group by d_w_id) a left join (Select w_id, w_ytd from bmsql_warehouse) b on a.d_w_id = b.w_id and a.d_ytd_sum = b.w_ytd where b.w_id is null;
执行压测
执行如下命令运行TPC-C测试:
cd benchmarksql/run ./runBenchmark.sh props.mysql
运行后可以看到实时的tpmC数值,运行结束后会显示平均的tpmC数值。
[2024/07/16 17:00:05.845] Average tpmC: 306979.98 Current tpmC: 308052.00 Memory Usage: 661MB / 3584MB [2024/07/16 17:00:10.845] Average tpmC: 307029.91 Current tpmC: 309876.00 Memory Usage: 1024MB / 3584MB [2024/07/16 17:00:15.845] Average tpmC: 307111.09 Current tpmC: 311820.00 Memory Usage: 429MB / 3584MB [2024/07/16 17:00:20.846] Average tpmC: 307108.95 Current tpmC: 306982.60 Memory Usage: 780MB / 3584MB 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, Measured tpmC (NewOrders) = 307058.27 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, Measured tpmTOTAL = 681928.39 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, Transaction Count = 3411539 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, Session Start = 2024-07-16 16:55:20 17:00:21,011 [Thread-508] INFO jTPCC : Term-00, Session End = 2024-07-16 17:00:21
测试结果
引擎版本MySQL 5.7
版本号:polardb-2.4.0_5.4.19-20240610_xcluster5.4.19-20240527,详情请参见:版本发布说明。
规格 | 64并发 | 128并发 | 256并发 | 512并发 | 1024并发 |
4C32G*2 | 91858.36 | 107268.04 | 108894.07 | 106442.37 | 98404.9 |
4C32G*4 | 117329.67 | 178425.44 | 206076.83 | 210437.44 | 209218.11 |
8C64G*2 | 106817.2 | 145097.95 | 156306.53 | 152141.55 | 138043.88 |
8C64G*4 | 117888.5 | 208051.75 | 296975.34 | 316085.12 | 307058.28 |
引擎版本MySQL 8.0
版本号:polardb-2.4.0_5.4.19-20240610_xcluster8.4.19-20240523,详情请参见:版本发布说明。
规格 | 64并发 | 128并发 | 256并发 | 512并发 | 1024并发 |
4C32G*2 | 71546.19 | 88074.26 | 85959.83 | 79893.78 | 67109.97 |
4C32G*4 | 88000.71 | 133363.91 | 166959.56 | 166549.16 | 158594.61 |
8C64G*2 | 89677.54 | 118498.21 | 117536.04 | 114574.98 | 101338.24 |
8C64G*4 | 101735.81 | 171088.45 | 240313.94 | 236207.55 | 203671.55 |