写点什么

使用 HyBench 测试 TiDB

  • 2024-01-19
    北京
  • 本文字数:6165 字

    阅读完需:约 20 分钟

作者: ShawnYan 原文来源:https://tidb.net/blog/5d216845



图片选自: https://asktug.com/t/topic/1020117


本文将介绍如何使用 HyBench 对 TiDB 进行测试,并简述 HyBench 适配 TiDB 的注意事项。


Hybench 是一款由中国软件评测中心、清华大学联合牵头,多家公司共同研发的 HTAP 数据库基准测试工具。


TiDB 是一款兼容 MySQL 的数据库,Hybench 已在 Gitee 开源,支持 MySQL 数据库,通过修改 HyBench 源码以适配 TiDB。

前置需求

  1. 为方便演示,这里直接启动一个 TiDB 本地测试集群。

  2. 准备 JDK 17,并配置环境变量。

  3. 安装 Maven。


直接使用 dnf 安装即可,版本信息如下。


[root@rocky9 ~]# mvn --versionApache Maven 3.6.3 (Red Hat 3.6.3-15)Maven home: /usr/share/mavenJava version: 17.0.9, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.9.0.9-2.el9.x86_64Default locale: en_US, platform encoding: UTF-8OS name: "linux", version: "5.14.0-362.13.1.el9_3.x86_64", arch: "amd64", family: "unix"
复制代码


运行测试

1. 修改数据库连接信息。

依据实际需求修改配置文件 conf/db.prop 中的 HOST, IP, USERNAME, PASSWORD 等信息。

2. 生成测试数据。

运行生成数据的命令:


./hybench -t gendata -c conf/db.prop
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t gendata -c conf/db.prop2024-01-16 23:07:30 [main] INFO  HyBench:324 - Hi~Bench, HyBench2024-01-16 23:07:30 [main] INFO  ConfigLoader:57 - ===============configuration==================2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - xapclient = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at2_percent = 252024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at1_percent = 352024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - apclient = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - xpRunMins = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at4_percent = 152024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - apround = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - url = jdbc:mysql://192.168.8.92:4000/hybench?useUnicode=true&characterEncoding=utf-82024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - tpRunMins = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at3_percent = 152024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - password = 2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - tpclient = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - fresh_interval = 202024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - sf = 1x2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - classname = com.mysql.cj.jdbc.Driver2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - xtpclient = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - apRunMins = 12024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at5_percent = 72024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - db = tidb2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - username = root2024-01-16 23:07:30 [main] INFO  ConfigLoader:59 - at6_percent = 32024-01-16 23:07:30 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:07:30 [main] INFO  ConfigLoader:62 - This is a data generator of HyBench, Version 0.1------------------------------------------------Data is generating...------------------------------------------------WARNING: dir:/root/hybench/Data_1x not exists! will created.Data generate not skipped!Data is ready under the Data folder!------------------------------------------------Data generation took 11831 msNo autoloader, do nothing!
复制代码


查看生成的数据文件:


[root@rocky9 Data_1x]# ll -htotal 11M-rw-r--r-- 1 root root 1.4M Jan 16 23:07 checkingAccount.csv-rw-r--r-- 1 root root 315K Jan 16 23:07 checking.csv-rw-r--r-- 1 root root 305K Jan 16 23:07 company.csv-rw-r--r-- 1 root root 3.6M Jan 16 23:07 customer.csv-rw-r--r-- 1 root root 320K Jan 16 23:07 loanApps.csv-rw-r--r-- 1 root root 411K Jan 16 23:07 loanTrans.csv-rw-r--r-- 1 root root 1.4M Jan 16 23:07 savingAccount.csv-rw-r--r-- 1 root root 3.2M Jan 16 23:07 transfer.csv[root@rocky9 Data_1x]# 
复制代码


3. 初始化表结构。

运行生成表结构的命令:


./hybench -t sql -f conf/tidb/ddl_tidb.sql -c conf/db.prop
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t sql -f conf/tidb/ddl_tidb.sql -c conf/db.prop2024-01-16 23:11:10 [main] INFO  HyBench:324 - Hi~Bench, HyBench...2024-01-16 23:11:10 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:11:10 [main] INFO  ConfigLoader:62 - 2024-01-16 23:11:11 [main] INFO  ExecSQL:58 - execute query:CREATE TABLE IF NOT EXISTS  customer (...
复制代码

4. 初始化表索引。

运行生成表索引的命令:


./hybench -t sql -f conf/tidb/create_index_tidb.sql -c conf/db.prop
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t sql -f conf/tidb/create_index_tidb.sql -c conf/db.prop2024-01-16 23:11:56 [main] INFO  HyBench:324 - Hi~Bench, HyBench...2024-01-16 23:11:56 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:11:56 [main] INFO  ConfigLoader:62 - 2024-01-16 23:11:58 [main] INFO  ExecSQL:58 - execute query:create index idx_loanapps_1 on loanapps ( applicantid );...
复制代码

5. 导入测试数据。

运行导入数据的命令:


./hybench -t sql -f conf/tidb/load_data_tidb.sql -c conf/db.prop
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t sql -f conf/tidb/load_data_tidb.sql -c conf/db.prop2024-01-16 23:30:20 [main] INFO  HyBench:324 - Hi~Bench, HyBench...2024-01-16 23:30:20 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:30:20 [main] INFO  ConfigLoader:62 - 2024-01-16 23:30:22 [main] INFO  ExecSQL:58 - execute query:LOAD DATA LOCAL INFILE 'Data_1x/customer.csv' INTO TABLE customer FIELDS TERMINATED BY ',';...
复制代码

6. 连接数据库,查看库表信息。

mysql --comments --host 192.168.8.92 --port 4000 -u rootuse hybenchshow tables;
复制代码


共导入 8 张表。


+-------------------+| Tables_in_hybench |+-------------------+| checking          || checkingAccount   || company           || customer          || loanapps          || loantrans         || savingAccount     || transfer          |+-------------------+8 rows in set (0.01 sec)
复制代码

7. 运行 TP 负载测试。

运行负载测试:


./hybench -t runtp -c conf/db.prop -f conf/tidb/stmt_tidb.toml
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t runtp -c conf/db.prop -f conf/tidb/stmt_tidb.toml2024-01-16 23:38:57 [main] INFO  HyBench:324 - Hi~Bench, HyBench2024-01-16 23:38:57 [main] INFO  ConfigLoader:57 - ===============configuration==================2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - xapclient = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at2_percent = 252024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at1_percent = 352024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - apclient = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - xpRunMins = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at4_percent = 152024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - apround = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - url = jdbc:mysql://192.168.8.92:4000/hybench?useUnicode=true&characterEncoding=utf-8&allowLoadLocalInfile=true2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - tpRunMins = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at3_percent = 152024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - password = 2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - tpclient = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - fresh_interval = 202024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - sf = 1x2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - classname = com.mysql.cj.jdbc.Driver2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - xtpclient = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - apRunMins = 12024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at5_percent = 72024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - db = tidb2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - username = root2024-01-16 23:38:57 [main] INFO  ConfigLoader:59 - at6_percent = 32024-01-16 23:38:57 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:38:57 [main] INFO  ConfigLoader:62 - 2024-01-16 23:38:58 [main] INFO  HyBench:61 - Begin TP Workload2024-01-16 23:38:58 [pool-3-thread-1] INFO  Client:263 - Begin to run :TPClient, Test Duration is 1 mins2024-01-16 23:39:04 [Thread-0] INFO  Client:297 - Transaction 3 : max rt : 38.0 | min rt :23.0 | avg rt : 28.33 | 95% rt : 38.00 | 99% rt : 38.00...2024-01-16 23:39:04 [Thread-0] INFO  Client:307 - Current 1/10 time TP TPS is 6.50...2024-01-16 23:39:58 [Thread-0] INFO  Client:307 - Current 10/10 time TP TPS is 10.882024-01-16 23:39:58 [pool-3-thread-1] INFO  Client:397 - Finished to execute TPClient2024-01-16 23:39:58 [main] INFO  HyBench:105 - TP Workload is done.2024-01-16 23:39:58 [main] INFO  HyBench:407 - Congs~ Test is done! Bye!====================Test Summary========================Test starts at 2024-01-16 23:38:58Test ends at 2024-01-16 23:39:58AP Concurrency is 0TP Concurrency is 1Total amount of TP Transaction is 654TPS is 10.9Query/Transaction response time(ms) histogram : ------------TP-------------------TP Transaction  1 : max rt :      30.00 | min rt :      15.00 | avg rt :      21.28 | 95% rt :      30.00 | 99% rt :      30.00 TP Transaction  2 : max rt :      59.00 | min rt :      16.00 | avg rt :      27.83 | 95% rt :      59.00 | 99% rt :      59.00 TP Transaction  3 : max rt :      43.00 | min rt :      17.00 | avg rt :      24.08 | 95% rt :      41.25 | 99% rt :      43.00 TP Transaction  4 : max rt :      47.00 | min rt :      14.00 | avg rt :      24.52 | 95% rt :      41.40 | 99% rt :      47.00 TP Transaction  5 : max rt :      76.00 | min rt :      23.00 | avg rt :      37.18 | 95% rt :      72.55 | 99% rt :      76.00 TP Transaction  6 : max rt :      55.00 | min rt :      18.00 | avg rt :      29.35 | 95% rt :      54.30 | 99% rt :      55.00 TP Transaction  7 : max rt :      99.00 | min rt :      17.00 | avg rt :      32.33 | 95% rt :      99.00 | 99% rt :      99.00 TP Transaction  8 : max rt :      47.00 | min rt :      14.00 | avg rt :      25.90 | 95% rt :      46.20 | 99% rt :      47.00 TP Transaction  9 : max rt :     107.00 | min rt :      50.00 | avg rt :      70.00 | 95% rt :      99.75 | 99% rt :     107.00 TP Transaction 10 : max rt :     683.00 | min rt :     214.00 | avg rt :     393.02 | 95% rt :     617.40 | 99% rt :     683.00 TP Transaction 11 : max rt :     108.00 | min rt :      45.00 | avg rt :      66.57 | 95% rt :      93.00 | 99% rt :     108.00 TP Transaction 12 : max rt :     111.00 | min rt :      41.00 | avg rt :      64.20 | 95% rt :      98.20 | 99% rt :     111.00 TP Transaction 13 : max rt :     267.00 | min rt :      70.00 | avg rt :     122.98 | 95% rt :     219.45 | 99% rt :     267.00 TP Transaction 14 : max rt :     256.00 | min rt :      70.00 | avg rt :     116.97 | 95% rt :     236.20 | 99% rt :     256.00 TP Transaction 15 : max rt :     101.00 | min rt :      46.00 | avg rt :      67.52 | 95% rt :      99.40 | 99% rt :     101.00 TP Transaction 16 : max rt :     209.00 | min rt :      65.00 | avg rt :     102.05 | 95% rt :     205.90 | 99% rt :     209.00 TP Transaction 17 : max rt :     150.00 | min rt :      48.00 | avg rt :      71.58 | 95% rt :     116.50 | 99% rt :     150.00 TP Transaction 18 : max rt :     124.00 | min rt :      46.00 | avg rt :      69.42 | 95% rt :     103.00 | 99% rt :     124.00 ====================Thank you!========================
复制代码

8. 清理测试表数据。

运行清理脚本:


./hybench -t sql -f conf/dropTables.sql -c conf/db.prop
复制代码


输出结果:


[root@rocky9 hybench]# ./hybench -t sql -f conf/dropTables.sql -c conf/db.prop2024-01-16 23:43:07 [main] INFO  HyBench:324 - Hi~Bench, HyBench...2024-01-16 23:43:07 [main] INFO  ConfigLoader:61 - ===============configuration==================2024-01-16 23:43:07 [main] INFO  ConfigLoader:62 - 2024-01-16 23:43:09 [main] INFO  ExecSQL:58 - execute query:drop table if exists customer;...
复制代码

注意事项

  1. HyBench 需要使用 JDK 17,这在 README 中有一处提及,全文搜索一下比较容易找到。


封装了 java 执行命令 (需要配置 jdk17)


  1. 目前,开源版本只支持 1X、10x 数据,后续在商业版本中会增加 100x,1000x 及更大规模的数据。


对应文件 src/main/resource/parameters.toml 中可以看到 [1x][10x]


  1. 导入数据使用的 SQL 命令为 LOAD DATA LOCAL INFILE,是 db.prop 配置文件中,JDBC 连接串需要增加参数 allowLoadLocalInfile=true

总结

本文基于开源数据库压测软件 HyBench 对 TiDB 进行适配,并做简单测试。


项目地址:shawnyan/hybench


如果没有特殊需求,优先推荐使用 TiUP bench 组件对 TiDB 进行压测。


发布于: 刚刚阅读数: 4
用户头像

TiDB 社区官网:https://tidb.net/ 2021-12-15 加入

TiDB 社区干货传送门是由 TiDB 社区中布道师组委会自发组织的 TiDB 社区优质内容对外宣布的栏目,旨在加深 TiDBer 之间的交流和学习。一起构建有爱、互助、共创共建的 TiDB 社区 https://tidb.net/

评论

发布
暂无评论
使用 HyBench 测试 TiDB_性能测评_TiDB 社区干货传送门_InfoQ写作社区