TiDB 热点测试
作者: magongyong 原文来源:https://tidb.net/blog/e32b9f2b
一、测试说明
1、环境信息
硬件信息:3 台物理机,1 个 tidb server(16c,64g),3 个 tikv(16c,64g,固态硬盘)
软件信息:centos7.5 + tidb v4.0.13
2、测试方法
sysbench:insert.lua(单条数据 insert),50 并发
3、测试案例
二、测试准备
1、主键自增热点测试
初始化:sysbench –db-driver=mysql /usr/share/sysbench/tests/include/oltp_legacy/insert.lua –mysql-host=10.100.xxx.xxx –mysql-port=4000 –mysql-user=u_sysbench –mysql-db=sbtest_incr –mysql-password=****** –oltp-test-mode=complex –oltp-tables-count=8 –oltp-table-size=10000 –threads=50 –time=600 –report-interval=5 prepare
测试:sysbench –db-driver=mysql /usr/share/sysbench/tests/include/oltp_legacy/insert.lua –mysql-host=10.100.xxx.xxx –mysql-port=4000 –mysql-user=u_sysbench –mysql-db=sbtest_incr –mysql-password=****** –oltp-test-mode=complex –oltp-tables-count=8 –oltp-table-size=10000 –threads=50 –time=600 –report-interval=5 run
2、主键随机热点测试
初始化:复制主键自增库(sbtest_incr)的建表语句,auto_increment 关键字改为 auto_random,共 8 个表
执行测试:sysbench –db-driver=mysql /usr/share/sysbench/tests/include/oltp_legacy/bulk_insert.lua –mysql-host=10.100.xxx.xxx –mysql-port=4000 –mysql-user=u_sysbench –mysql-db=sbtest_rand –mysql-password=****** –oltp-test-mode=complex –oltp-tables-count=8 –oltp-table-size=10000 –threads=50 –time=600 –report-interval=5 run
3、主键随机,并根据主键范围切割表热点测试
初始化:复制主键自增库(sbtest_incr)的建表语句,auto_increment 关键字改为 auto_random,共 8 个表
表切割:split table sbtest1 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest2 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest3 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest4 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest5 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest6 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest7 between (1000000000000000000) and (9223372036854775807) regions 10;split table sbtest8 between (1000000000000000000) and (9223372036854775807) regions 10;
执行测试:sysbench –db-driver=mysql /usr/share/sysbench/tests/include/oltp_legacy/insert.lua –mysql-host=10.100.xxx.xxx –mysql-port=4000 –mysql-user=u_sysbench –mysql-db=sbtest_split –mysql-password=****** –oltp-test-mode=complex –oltp-tables-count=8 –oltp-table-size=10000 –threads=50 –time=600 –report-interval=5 run
4、主键随机和主键随机并切割表的库初始化表结构语句
sbtest_rand 和 sbtest_split_rand 库初始化表结构:
CREATE TABLE sbtest1 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_1 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest2 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_2 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest3 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_3 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest4 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_4 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest5 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_5 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest6 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_6 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest7 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_7 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE sbtest8 (id bigint NOT NULL auto_random,k int(10) NOT NULL DEFAULT ‘0’,c char(120) NOT NULL DEFAULT “,pad char(60) NOT NULL DEFAULT “,PRIMARY KEY (id),KEY k_8 (k)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
5、指标查看
查看 region 的 sql:SELECT b.TABLE_NAME,b.REGION_ID,IS_INDEX,INDEX_ID,b.start_key,b.end_keyFROM information_schema.TABLES as aINNER JOIN information_schema.TIKV_REGION_STATUS as bWHERE a.TIDB_TABLE_ID = b.TABLE_IDAND a.TABLE_SCHEMA=‘sbtest’ AND a.TABLE_NAME=‘sbtest1’order by region_id desc;
dashboard- 流量可视化查看热点情况
dashboard- 慢查询查看 sql 运行情况
grafana 查看系统负载情况
三、测试过程
1、主键自增热点测试
sysbench 报告:
热点情况,一条亮线,写入集中:
cpu 负载,波动较大,不太均衡:
2、主键随机热点测试
sysbench 报告:
热点情况,一条亮线,写入集中:
cpu 负载,波动较大,不太均衡:
3、主键随机,表切割为 10 个 region
sysbench 报告:
热点情况,均匀写入:
cpu 负载,tikv 均衡:
四、测试结论
1、测试结果对比
2、测试结果说明
主键改为随机并不能提升性能,反而有所降低
主键改为随机,并且表切割为 10 个 region 并不能提升性能,反而有所降低
主键改为随机,表不做切割,热点问题依旧存在
主键改为随机,表切割为 10 个 region,热点问题有较大改善
3、测试结果分析
在 pctp 的视频中,老师测试的结果是随机写入要比顺序写入快,我以相同的场景测试很多次,而且业务侧也试过很多次,发现在 4.0.13 这个版本下,确实顺序写入要比随机写入要快。但是随机写入确实有助于降低热点,不会导致出现 tikv write stall 现象。
版权声明: 本文为 InfoQ 作者【TiDB 社区干货传送门】的原创文章。
原文链接:【http://xie.infoq.cn/article/7347a2fbbd9613480980d8f12】。文章转载请联系作者。
评论