【工具/性能】开源的性能测试工具sysbench
文章目录
- 概述
- 安装
- 使用
- 测试 fileio
- 测试 CPU
- 测试 memory
- 测试 threads
- 测试 mutex
- 测试 otlp
- 对 MySQL 事务型 OLTP 的测试:
- 来源
概述
sysbensh是一个非常通用的benchmark工具,其提供多种方面的测试:
- cpu :提供一个简单的cpu benchmark测试
- fileio:文件磁盘io的benchmark测试
- memory:内存访问 benchmark测试
- thread:线程调度 benchmark测试
- mutex:POSIX的锁 benchmark测试
- OLTP:数据库 benchmark测试,支持MySQL,Pgsql
安装
默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数.
1.安装环境
CentOS release 6.3 (Final)
MySQL 5.6.13
MySQL_HOME=/usr/local/mysql/
Sysbench 0.4.12
2.下载安装包
# wget http://sourceforge.net/projects/sysbench/sysbench-0.4.12.tar.gz
3.编译安装
# tar –zxvf sysbench-0.4.12.tar.gz进入解压缩包sysbench-0.4.12,并执行脚本autogen.sh# cd sysbench-0.4.12# ./autogen.sh关键的三步:configure && make && make install首先是./configure命令,sysbench默认是支持MySQL的benchmarking的,如果不加任何选项则要求保证MySQL的安装路径都是默认的标准路径,headfile位于/usr/include目录下,libraries位于/usr/lib/目录下。因为我的MySQL是源码编译安装的,安装路径是放在/usr/local/mysql下,所以这里要添加相应的选项命令:
# ./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \--with-mysql-includes=/usr/local/mysql/include/mysql/ \--with-mysql-libs=/usr/local/mysql/lib/mysql/注意:这里在编译时要将路径写到最后的include/mysql及lib/mysql,如下所示:–with-mysql-includes=/usr/local/mysql/include/mysql/--with-mysql-libs=/usr/local/mysql/lib/mysql/因为网上好多资料都没有提到这一层,在编译时总是编译不过去,这里浪费了好多精力。接下来执行如下命令:
# make && make install
4.yum安装
如果觉得源码安装麻烦,也可以采用yum安装,操作如下:
# yum install -y sysbench
使用
为了更加熟悉使用sysbench,我们需要熟悉一些通用的 options参数
--threads=N 线程数目,默认使用1
--events=N 默认为0
--time=N 默认为0
--forced-shutdown=STRING 默认为‘off’,另一个选项为‘on’
--thread-stack-size=SIZE 默认为64K
--rate=N 平均transactions率,默认为0,不限制
--report-interval=N 周期性(periodically)汇报统计信息,单位seconds,默认为0,表示disable interval report
--debug[=on|off] print debug 信息,默认为off
还有一些其他的参数,因为很少使用所有就不介绍了。
语法表达式
sysbench [options]... [testname] [command]
其中testname,可以是fileio,memory等,或者是一个lua script或者是lua script的path。
command表示prepare,run,cleanup或者help
具体详细的每一个options参数的含义,参考github。
测试 fileio
sysbench --test=fileio help参数详解:--file-num=N 代表生成测试文件的数量,默认为128。--file-block-size=N 测试时所使用文件块的大小,如果想磁盘针对innodb存储引擎进行测试,可以将其设置为16384,即innodb存储引擎页的大小。默认为16384。--file-total-size=SIZE 创建测试文件的总大小,默认为2G大小。--file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)。--file-io-mode=STRING 文件操作的模式,sync(同步),async(异步),fastmmap(快速mmap),slowmmap(慢速mmap),默认为sync同步模式。--file-async-backlog=N 对应每个线程队列的异步操作数,默认为128。--file-extra-flags=STRING 打开文件时的选项,这是与API相关的参数。--file-fsync-freq=N 执行fsync()函数的频率。fsync主要是同步磁盘文件,因为可能有系统和磁盘缓冲的关系。 0代表不使用fsync函数。默认值为100。--file-fsync-all=[on|off] 每执行完一次写操作,就执行一次fsync。默认为off。--file-fsync-end=[on|off] 在测试结束时执行fsync函数。默认为on。--file-fsync-mode=STRING文件同步函数的选择,同样是和API相关的参数,由于多个操作系统对于fdatasync支持不同,因此不建议使用fdatasync。默认为fsync。--file-merged-requests=N 大多情况下,合并可能的IO的请求数,默认为0。--file-rw-ratio=N 测试时的读写比例,默认时为1.5,即可3:2
测试 CPU
sysbench --test=cpu help参数详解:--cpu-max-prime=N 用来选项指定最大的素数,具体参数可以根据CPU的性能来设置,默认为10000
测试 memory
sysbench --test=memory help参数详解:--memory-block-size=SIZE 测试内存块的大小,默认为1K--memory-total-size=SIZE 数据传输的总大小,默认为100G--memory-scope=STRING 内存访问的范围,包括全局和本地范围,默认为global--memory-hugetlb=[on|off] 是否从HugeTLB池分配内存的开关,默认为off--memory-oper=STRING 内存操作的类型,包括read, write, none,默认为write--memory-access-mode=STRING 内存访问模式,包括seq,rnd两种模式,默认为seq
测试 threads
sysbench --test-threads help参数详解: --thread-yields=N 指定每个请求的压力,默认为1000--thread-locks=N 指定每个线程的锁数量,默认为8
测试 mutex
sysbench --test=mutex help参数详解:--mutex-num=N 数组互斥的总大小。默认是4096--mutex-locks=N 每个线程互斥锁的数量。默认是50000--mutex-loops=N 内部互斥锁的空循环数量。默认是10000
测试 otlp
sysbench --test=otlp help参数详解:--oltp-test-mode=STRING 执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex--oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session--oltp-sp-name=STRING 存储过程的名称。默认为空--oltp-read-only=[on|off] 只读模式。Update,delete,insert语句不可执行。默认是off--oltp-skip-trx=[on|off] 省略begin/commit语句。默认是off--oltp-range-size=N 查询范围。默认是100--oltp-point-selects=N number of point selects [10]--oltp-simple-ranges=N number of simple ranges [1]--oltp-sum-ranges=N number of sum ranges [1]--oltp-order-ranges=N number of ordered ranges [1]--oltp-distinct-ranges=N number of distinct ranges [1]--oltp-index-updates=N number of index update [1]--oltp-non-index-updates=N number of non-index updates [1]--oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} [select]--oltp-auto-inc=[on|off] AUTO_INCREMENT是否开启。默认是on--oltp-connect-delay=N 在多少微秒后连接数据库。默认是10000--oltp-user-delay-min=N 每个请求最短等待时间。单位是ms。默认是0--oltp-user-delay-max=N 每个请求最长等待时间。单位是ms。默认是0--oltp-table-name=STRING 测试时使用到的表名。默认是sbtest--oltp-table-size=N 测试表的记录数。默认是10000--oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special--oltp-dist-iter=N 产生数的迭代次数。默认是12--oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是1--oltp-dist-res=N ‘special’的百分比值。默认是75
对 MySQL 事务型 OLTP 的测试:
对于 MySQL 的 OLTP 测试,和 File 一样,同样需要经历 prepare,run,cleanup 三个阶段。
prepare 准备阶段
prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:[root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --db-driver=mysql --mysql-socket=/data/mysqlsoft3307/mysql.sock --mysql-user=dba_manager --mysql-password='111111' --mysql-db=test preparesysbench 0.4.12: multi-threaded system evaluation benchmarkCreating table 'sbtest'...Creating 10 records in table 'sbtest'...
run运行测试
接下来对上面产生的表进行 oltp 的测试:[root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --oltp-read-only=off --init-rng=on --num-threads=16
--max-requests=0 --oltp-dist-type=uniform --max-time=3600 --mysql-user=dba_manager --mysql-password='111111' --db-driver=mysql
--mysql-socket=/data/mysqlsoft3307/mysql.sock run > result.log参数说明:--max-time=3600 指定测试时长为1小时--mysql-db=test 指定测试的数据库名[root@db-master sysbench]# cat result.log sysbench 0.4.12: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Initializing random number generator from timer.Doing OLTP test.Running mixed OLTP testUsing Uniform distributionUsing "BEGIN" for starting transactionsUsing auto_inc on the id columnThreads started!Time limit exceeded, exiting...(last message repeated 15 times)Done.OLTP test statistics:queries performed:read: 137346874write: 49052449other: 19620980total: 206020303transactions: 9810489 (2725.13 per sec.)deadlocks: 2 (0.00 per sec.)read/write requests: 186399323 (51777.50 per sec.)other operations: 19620980 (5450.26 per sec.)Test execution summary:total time: 3600.0060stotal number of events: 9810489total time taken by event execution: 57542.1464per-request statistics:min: 3.00msavg: 5.87msmax: 212.09msapprox. 95 percentile: 8.44msThreads fairness:events (avg/stddev): 613155.5625/1486.47execution time (avg/stddev): 3596.3842/0.01transactions代表测试结果的评判标准即TPS.
上述测试结果是 2725.13 per sec.
来源
Sysbench
sysbench基础介绍
sysbench压力测试工具简介
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
