使用 TiUP bench 组件压测 TiDB

在测试数据库性能时,经常需要对数据库进行压测,为了满足这一需求,TiUP 集成了 bench 组件。目前,TiUP bench 组件提供 TPC-C 和 TPC-H 两种压测的 workload,其命令参数如下,更多信息请参考 TPC 官方网站。

1. tiup bench
1. Benchmark database with different workloads

3. Usage:
4. tiup bench [command]

6. Available Commands:
7. help        帮助信息
8. tpcc        以 TPC-C 作为 workload 压测
9. tpch        以 TPC-H 作为 workload 压测

11. Flags:
12. --count int           总执行次数, 0 表示无限次
13. -D, --db string           被压测数据库名称 (默认为 "test")
14. -d, --driver string       数据库驱动: mysql
15. --dropdata            在 prepare 之前清除历史数据
16. -h, --help                bench 命令自身的帮助信息
17. -H, --host string         数据库的主机地址 (默认 "127.0.0.1")
18. --ignore-error        忽略压测时数据库报出的错误
19. --interval duration   两次报告输出时间的间隔 (默认 10s)
20. --isolation int       隔离级别 0: Default, 1: ReadUncommitted,
21. 2: ReadCommitted, 3: WriteCommitted, 4: RepeatableRead,
22. 5: Snapshot, 6: Serializable, 7: Linerizable
23. --max-procs int       runtime.GOMAXPROCS
24. -p, --password string     数据库密码
25. -P, --port int            数据库端口 (默认 4000)
26. --pprof string        pprof 地址
27. --silence             压测过程中不打印错误信息
28. --summary             只打印 Summary
29. -T, --threads int         压测并发线程数 (默认 16)
30. --time duration       总执行时长 (默认 2562047h47m16.854775807s)
31. -U, --user string         压测时使用的数据库用户 (默认 "root")

下文分别介绍如何使用 TiUP 运行 TPC-C 测试和 TPC-H 测试。

使用 TiUP 运行 TPC-C 测试

TiUP bench 组件支持如下运行 TPC-C 测试的命令和参数:

1. Available Commands:
2. check       检查数据一致性
3. cleanup     清除数据
4. prepare     准备数据
5. run         开始压测

7. Flags:
8. --check-all        运行所有的一致性检测
9. -h, --help             tpcc 的帮助信息
10. --parts int        分区仓库 的数量(默认 1)
11. --warehouses int   仓库的数量 (默认 10)

TPC-C 测试步骤

  1. 通过 HASH 使用 4 个分区创建 4 个仓库:

1. tiup bench tpcc --warehouses 4 --parts 4 prepare 2. 运行 TPC-C 测试:

1. tiup bench tpcc --warehouses 4 run 3. 清理数据:

1. tiup bench tpcc --warehouses 4 cleanup 4. 检查一致性:

1. tiup bench tpcc --warehouses 4 check 5. 生成 CSV 文件:

1. tiup bench tpcc --warehouses 4 prepare --output-dir data --output-type=csv 6. 为指定的表生成 CSV 文件:

1. tiup bench tpcc --warehouses 4 prepare --output-dir data --output-type=csv --tables history,orders

使用 TiUP 运行 TPC-H 测试

TiUP bench 组件支持如下运行 TPC-H 测试的命令和参数:

1. Available Commands:
2. cleanup     清除数据
3. prepare     准备数据
4. run         开始压测

6. Flags:
7. --check            检查输出数据,只有 scale 因子为 1 时有效
8. -h, --help             tpch 的帮助信息
9. --queries string   所有的查询语句 (默认 "q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20,q21,q22")
10. --sf int           scale 因子

TPC-H 测试步骤

  1. 准备数据:

1. tiup bench tpch --sf=1 prepare 2. 运行 TPC-H 测试,根据是否检查结果执行相应命令:

  • 检查结果:

    1. tiup bench tpch --sf=1 --check=true run - 不检查结果:

    1. tiup bench tpch --sf=1 run 3. 清理数据:

1. tiup bench tpch cleanup