Sysbench 说明
Sysbench是一款开源的、模块化的、跨平台的多线程性能测试工具,可以执行数据库、CPU、内存、线程、IO等方面的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下验证PolarDB-X在Sysbench OLTP和SELECT场景中的性能表现。
测试设计
- 购买PolarDB-X、ECS、RDS。
- PolarDB-X(4种规格):入门版8C32G、标准版16C64G、企业版32C128G、企业版64C256G。
- ECS压力机(1台):32C64G、操作系统 Aliyun Linux 2.1903 64位、计算网络增强型。
- RDS(12台):16C64G、MySQL 5.7、独享型。
- 备注:DRDS、ECS、RDS都处于同一可用区,同一VPC。
- 在PolarDB-X控制台创建水平拆分库,选择已经购买的12台RDS。
- 在ECS安装Sysbench,并准备1.6亿数据。关于如何使用Sysbench,请参见Sysbench使用指南。
测试参数说明
--test='/usr/local/share/sysbench/oltp_drds.lua' OLTP场景使用oltp_drds.lua, SELECT场景使用select.lua--mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(id) tbpartitions 2'PolarDB-X分库分表语法,表示每个分库2张分表。--oltp-table-size=160000000 准备1.6亿数据。--oltp_auto_inc=off 关闭自增主键。--oltp_skip_trx=on 跳过事务。--oltp_secondary 将ID设置为非主键防止主键冲突。--oltp_range_size=5连续取值5个,必定走到5个分片。--rand-init=on 每个测试表都是用随机数据来填充的sysbench。--num-threads=200具体每个场景的并发数详情请参见结果表格。
测试语句范例:
sysbench --test='/usr/local/share/sysbench/oltp_drds.lua'--oltp_tables_count=1--report-interval=5--oltp-table-size=160000000 --mysql-user=****--mysql-password=****--mysql-table-engine=innodb --rand-init=on --mysql-host=****--mysql-port=3306--mysql-db=****--max-requests=0 --oltp_skip_trx=on --oltp_auto_inc=off --oltp_secondary --oltp_range_size=5--mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(id) tbpartitions 2' --num-threads=200--max-time=300 run
OLTP 测试结果
| 规格 | 并发数 | 每秒 read/write 数量 |
| 入门版 8C32G | 100 | 20807.12 |
| 标准版 16C64G | 230 | 49667.48 |
| 企业版 32C128G | 450 | 90693.70 |
| 企业版 64C256G | 900 | 177506.48 |
SELECT 测试结果
| 规格 | 并发数 | 每秒 read/write 数量 |
| 入门版 8C32G | 200 | 41401 |
| 标准版 16C64G | 300 | 98182.26 |
| 企业版 32C128G | 600 | 180500.00 |
| 企业版 64C256G | 1200 | 366863.48 |
OLTP 场景测试脚本详情
pathtest = string.match(test,"(.*/)")if pathtest thendofile(pathtest .."common.lua")elserequire("common")endfunction get_range_end(start)return start + oltp_range_size -1endfunction thread_init(thread_id)set_vars()if(((db_driver =="mysql") or (db_driver =="attachsql")) and mysql_table_engine =="myisam")thenlocal ilocal tables ={}for i=1, oltp_tables_count dotables[i]= string.format("sbtest%i WRITE", i)endbegin_query ="LOCK TABLES ".. table.concat(tables," ,")commit_query ="UNLOCK TABLES"elsebegin_query ="BEGIN"commit_query ="COMMIT"endendfunction event(thread_id)local rslocal ilocal table_namelocal range_startlocal c_vallocal pad_vallocal querytable_name ="sbtest".. sb_rand_uniform(1, oltp_tables_count)if not oltp_skip_trx thendb_query(begin_query)endif not oltp_write_only thenfor i=1, oltp_point_selects dors = db_query("SELECT c FROM ".. table_name .." WHERE id=".. sb_rand(1, oltp_table_size))endif oltp_range_selects thenfor i=1, oltp_simple_ranges dorange_start = sb_rand(1, oltp_table_size)rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN ".. range_start .." AND ".. get_range_end(range_start))endfor i=1, oltp_sum_ranges dorange_start = sb_rand(1, oltp_table_size)rs = db_query("SELECT SUM(K) FROM ".. table_name .." WHERE id BETWEEN ".. range_start .." AND ".. get_range_end(range_start))endfor i=1, oltp_order_ranges dorange_start = sb_rand(1, oltp_table_size)rs = db_query("SELECT c FROM ".. table_name .." WHERE id BETWEEN ".. range_start .." AND ".. get_range_end(range_start).." ORDER BY c")endfor i=1, oltp_distinct_ranges dorange_start = sb_rand(1, oltp_table_size)rs = db_query("SELECT DISTINCT c FROM ".. table_name .." WHERE id BETWEEN ".. range_start .." AND ".. get_range_end(range_start).." ORDER BY c")endendendif not oltp_read_only thenfor i=1, oltp_index_updates dors = db_query("UPDATE ".. table_name .." SET k=k+1 WHERE id=".. sb_rand(1, oltp_table_size))endfor i=1, oltp_non_index_updates doc_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")query ="UPDATE ".. table_name .." SET c='".. c_val .."' WHERE id=".. sb_rand(1, oltp_table_size)rs = db_query(query)if rs thenprint(query)endendfor i=1, oltp_delete_inserts doi = sb_rand(1, oltp_table_size)rs = db_query("DELETE FROM ".. table_name .." WHERE id=".. i)c_val = sb_rand_str([[###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])pad_val = sb_rand_str([[###########-###########-###########-###########-###########]])rs = db_query("INSERT INTO ".. table_name .. " (id, k, c, pad) VALUES ".. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size), c_val, pad_val))endend -- oltp_read_onlyif not oltp_skip_trx thendb_query(commit_query)endend

