推特 阿里云技术文档正文

Sysbench 使用指南_性能指标_分布式关系型数据库 DRDS

admin 阿里云技术文档 2020-02-11 197 0
阿里云服务器优惠

Sysbench 使用指南

DRDS 性能测试使用 Sysbench 作为压测工具,本文介绍 Sysbench 的使用方法。

安装

测试使用的是 Sysbench 0.5 版本,安装方法如下:

  1. git clone https://github.com/akopytov/sysbench.git
  2. git checkout 0.5
  3. yum -y install make automake libtool pkgconfig libaio-devel
  4. yum -y install mariadb-devel
  5. ./autogen.sh
  6. ./configure
  7. make -j
  8. make install

注意:以上是在压测 ECS 上的安装方法,如果需要安装到其他操作系统,参考 Sysbench 官方文档

安装完毕后,所有自带压测脚本都在 /usr/local/share/sysbench 目录下,DRDS 性能测试将使用该目录下的脚本。除此之外,也可以在源码目录 sysbench/sysbench/tests/db 下找到对应的压测脚本。

使用简介

常用测试模型

Sysbench 通过脚本定义了若干常用的压测模型,以下简单介绍几个常用模型:

压测模型 描述
bulk_inert.lua 批量插入数据
insert.lua 单值插入数据
delete.lua 删除数据
oltp.lua 混合读写测试,读写比例14:4
select.lua 简单的主键查询

表结构

对 DRDS 进行测试时,对 Sysbench 的测试表稍作改造,将其修改为分库分表的形式,测试表的建表语句如下:

  1. CREATE TABLE `sbtest1` (
  2. `id` int(10) unsigned NOT NULL,
  3. `k` int(10) unsigned NOT NULL DEFAULT '0',
  4. `c` char(120) NOT NULL DEFAULT '',
  5. `pad` char(60) NOT NULL DEFAULT '',
  6. KEY `xid` (`id`),
  7. KEY `k_1` (`k`)
  8. ) dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 4

以上建表语句中,分库分表数可自行调整,该表会在准备数据阶段自动生成,无需手动创建。

测试命令及参数

使用 Sysbench 进行压测,通常分为三个步骤:

  • prepare,准备数据
  • run,运行测试模型
  • cleanup,清理测试数据

通常仅需准备一次数据,在此数据基础上测试各种模型即可。

常用参数

Sysbench 中常用的参数如下:

  • --oltp-tables-count=1:表数量
  • --oltp-table-size=10000000:每个表产生的记录行数
  • --oltp-read-only=off:是否生成只读SQL,默认 off,如果设置为 on,则 oltp 模型不会生成 update, delete, insert 的 SQL 语句
  • --oltp-skip-trx=[on|off]:省略 BEGIN / COMMIT 语句。默认是 off
  • --rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同
  • --num-threads=12: 并发线程数,可以理解为模拟的客户端并发连接数
  • --report-interval=10:表示每 10s 输出一次性能数据
  • --max-requests=0:压力测试产生请求的总数,如果以下面的 max-time 来记,这个值设为 0 即可
  • --max-time=120:测试的持续时间
  • --oltp_auto_inc=off:id 是否为自增列
  • --oltp_secondary=on:将 id 设置为非主键防止主键冲突
  • --oltp_range_size=5: 连续取值 5 个,必定走到 5 个分片
  • --mysql_table_options='dbpartition by hash(id) tbpartition by hash(id) tbpartitions 2':DRDS 支持拆分表,在建表的时候需要指定拆分方式

示例命令

以下是示例命令,供参考:

准备数据:

  1. sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp_tables_count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb --rand-init=on --mysql-host=**** --mysql-port=*** --mysql-db=*** --max-time=300 --max-requests=0 --oltp_skip_trx=on --oltp_auto_inc=off --oltp_secondary=on --oltp_range_size=5 --mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 2' --num-threads=200 prepare

执行测试

  1. sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp_tables_count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb --rand-init=on --mysql-host=**** --mysql-port=*** --mysql-db=*** --max-time=300 --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 run

清理环境

  1. sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp_tables_count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb --rand-init=on --mysql-host=**** --mysql-port=*** --mysql-db=*** --max-time=300 --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 cleanup
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论

-----