sysbench压力测工具

sysbench介绍

sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。关于这个项目的详细介绍请看:https://github.com/akopytov/sysbench 。
它主要包括以下几种方式的测试:

  1. cpu性能

  2. 磁盘io性能

  3. 调度程序性能

  4. 内存分配及传输速度

  5. POSIX线程性能

  6. 数据库性能(OLTP基准测试)

sysbench的数据库OLTP测试支持MySQL、PostgreSQL、Oracle,目前主要用于Linux操作系统,开源社区已经将sysbench移植到了Windows,并支持SQL Server的基准测试。

安装sysbench

环境介绍

[root@DB-1 ~]# uname -r

2.6.32-642.el6.x86_64

[root@DB-1 ~]# uname -m

x86_64

[root@DB-1 ~]# cat /etc/redhat-release

CentOS release 6.8 (Final)

yum安装

centos安装

yum -y install sysbench

编译安装

下载sysbench的包

https://github.com/akopytov/sysbench

安装博客

http://www.cnblogs.com/lj95801/p/5942841.html

本篇安装是采用yum安装的,sysbench版本如下

sysbench --version

sysbench 1.0.9 

sysbench命令参数说明

常规命令参数

当我们在命令行执行sysbench --help会发现很多的参数常用的就那么几个

语法

 sysbench [options]... [testname] [command]

常规选项

General options:

  --threads=N                     number of threads to use [1]

  --events=N                      limit for total number of events [0]

  --time=N                        limit for total execution time in seconds [10]

  --forced-shutdown=STRING        number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]

  --thread-stack-size=SIZE        size of stack per thread [64K]

  --rate=N                        average transactions rate. 0 for unlimited rate [0]

  --report-interval=N             periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]

  --report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []

  --debug[=on|off]                print more debugging info [off]

  --validate[=on|off]             perform validation checks where possible [off]

  --help[=on|off]                 print help and exit [off]

  --version[=on|off]              print version and exit [off]

  --config-file=FILENAME          File containing command line options

  --tx-rate=N                     deprecated alias for --rate [0]

  --max-requests=N                deprecated alias for --events [0]

  --max-time=N                    deprecated alias for --time [0]

  --num-threads=N                 deprecated alias for --threads [1]

 

--threads=N   创建测试线程的数目。默认为1.

--events=N    事件总数的限制

--time=N   执行时间,单位是s。默认是0,不限制。

--forced-shutdown=STRING  超过max-time强制中断。默认是off。]

--thread-stack-size=SIZE   每个线程的堆栈大小。默认是64K。

--rate=N   平均事务率。0为无限的速度

--max-requests=N   请求的最大数目。默认为10000,0代表不限制。

--report-interval=N 定期报告中间统计数据,以秒为单位指定时间间隔。0禁用中间报告[0]

--debug=[on|off]    是否显示更多的调试信息。默认是off。

--validate=[on|off]   在可能情况下执行验证检查。默认是off。

--config-file=FILENAME  包含命令行选项的文件

指令说明

prepare(测试前准备工作)

run(正式测试)

cleanup(测试后删掉测试数据)

help version

测试文件I/O参数

[root@localhost bin]# sysbench fileio help                       

  --file-num=N   创建测试文件的数量。默认是128

  --file-block-size=N  测试时文件块的大小。默认是16384(16K)

  --file-total-size=SIZE   测试文件的总大小。默认是2G

  --file-test-mode=STRING  文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}

  --file-io-mode=STRING   文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync

  --file-extra-flags=STRING   使用额外的标志来打开文件{sync,dsync,direct} 。默认为空

  --file-fsync-freq=N   执行fsync()的频率。(0 – 不使用fsync())。默认是100

  --file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off

  --file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on

  --file-fsync-mode=STRING  使用哪种方法进行同步{fsync, fdatasync}。默认是fsync

  --file-merged-requests=N   如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0

--file-rw-ratio=N     测试时的读写比例。默认是1.5

测试CPU参数

你会发现就一个参数

[root@localhost bin]# sysbench cpu help  

  --cpu-max-prime=N  最大质数发生器数量。默认是10000

测试内存分配和传输速度参数

[root@localhost bin]# ./sysbench memory help

  --memory-block-size=SIZE  测试时内存块大小。默认是1K

  --memory-total-size=SIZE    传输数据的总大小。默认是100G

  --memory-scope=STRING    内存访问范围{global,local}。默认是global

  --memory-hugetlb=[on|off]  从HugeTLB池内存分配。默认是off

  --memory-oper=STRING     内存操作类型。{read, write, none} 默认是write

  --memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq

测试线程的参数

[root@localhost bin]# sysbench --test=threads help

  --thread-yields=N   每个请求产生多少个线程。默认是1000

  --thread-locks=N    每个线程的锁的数量。默认是8

utex性能测试

[root@localhost bin]# sysbench mutex help

  --mutex-num=N    数组互斥的总大小。默认是4096

  --mutex-locks=N    每个线程互斥锁的数量。默认是50000

  --mutex-loops=N    内部互斥锁的空循环数量。默认是10000

测试数据库性能的参数

这里关于数据库性能的参数是老版本的参数,要用请对照help的参数进行使用

[root@localhost bin]# sysbench --test=oltp help

oltp options:

  --oltp-test-mode=STRING    执行模式{simple,complex(advancedtransactional),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

 

General database options:

  --db-driver=STRING  指定数据库驱动程序('help' to get list of available drivers)

  --db-ps-mode=STRING编制报表使用模式{auto, disable} [auto]

Compiled-in database drivers:

    mysql - MySQL driver

mysql options:

  --mysql-host=[LIST,...]       MySQL server host [localhost]

  --mysql-port=N                MySQL server port [3306]

  --mysql-socket=STRING         MySQL socket

  --mysql-user=STRING           MySQL user [sbtest]

  --mysql-password=STRING       MySQL password []

  --mysql-db=STRING             MySQL database name [sbtest]

  --mysql-table-engine=STRING   storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]

  --mysql-engine-trx=STRING     whether storage engine used is transactional or not {yes,no,auto} [auto]

  --mysql-ssl=[on|off]          use SSL connections, if available in the client library [off]

  --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]

  --mysql-create-options=STRING additional options passed to CREATE TABLE []

sysbench的使用

通过sysbench测试cpu

sysbench cpu --cpu-max-prime=1500 run

当我们执行了上面的这条命令会得到如下的输出结果

 

General statistics:

    total time:                          10.0001s

    total number of events:              138094

 

Latency (ms):

         min:                                  0.07

         avg:                                  0.07

         max:                                  2.28

         95th percentile:                      0.08

         sum:                               9963.33

 

Threads fairness:

    events (avg/stddev):           138094.0000/0.00

    execution time (avg/stddev):   9.9633/0.00

 

从total time: 一行可以看出在求得1500以内的最大素数时使用了10.0001s 当然我这实验用的不是服务器

线程测试

sysbench  threads -threads=500 --thread-yields=100 --thread-locks=4 run

Test execution summary:

    total time:                          1.6930s

    total number of events:              10000

    total time taken by event execution: 829.6164

    per-request statistics:

         min:                                  0.08ms

         avg:                                 82.96ms

         max:                                471.16ms

         approx.  95 percentile:             206.11ms

Threads fairness:

    events (avg/stddev):           20.0000/7.45

    execution time (avg/stddev):   1.6592/0.01

I/O测试

    (1)prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。

    #sysbench fileio --file-num=10 --threads=16 --file-total-size=10G --file-test-mode=rndrw prepare

    --num-threads 开启的线程

    --file-total-size 总的文件大小

    (2)run阶段

    #sysbench fileio --file-num=10 --threads=200 --file-total-size=10G --file-test-mode=rndrw run    

    --file-test-mode

        rndrw:合并的随机读写

        rndwr:随机写入

        rndrd:随机读取

        seqrewr:顺序重写

        seqwr:顺序写

# w

 22:54:14 up  5:48,  2 users,  load average: 6.22, 6.04, 3.25

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

root     pts/1    10.0.0.1         21:53    5:35  20.07s 19.61s sysbench fileio --file-

root     pts/2    10.0.0.1         22:53    1.00s  0.05s  0.01s w

# w

 22:58:49 up  5:53,  2 users,  load average: 0.25, 2.66, 2.54

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

root     pts/1    10.0.0.1         21:53    1:43   0.48s  0.48s -bash

root     pts/2    10.0.0.1         22:53    0.00s  0.06s  0.00s w

 

    (3)清理测试时生成的文件

    #sysbench fileio --num-threads=200 --file-total-size=10G --file-test-mode=rndrw cleanup

内存测试

#sysbench memory --memory-block-size=8k --memory-total-size=4G run

General statistics:

    total time:                          0.3405s

    total number of events:              524288

 

Latency (ms):

         min:                                  0.00

         avg:                                  0.00

         max:                                  0.27

         95th percentile:                      0.00

         sum:                                265.76

 

Threads fairness:

    events (avg/stddev):           524288.0000/0.00

execution time (avg/stddev):   0.2658/0.00

数据库测试

mysql> create database sbtest;

准备测试使用的数据,我准备了1000W行数据

# sysbench --test=oltp --mysql-user=root --mysql-host=localhost --mysql-socket=/tmp/mysql.sock --mysql-password=  --mysql-table-engine=innodb --oltp-table-size=10000000 prepare    

 

#使用16个线程开始测试,读写模式。

#sysbench  --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mysql-table-engine=innodb --oltp-table-size=10000000 --db-ps-mode=disable  --mysql-user=root --mysql-host=localhost --mysql-socket=/tmp/mysql.sock  --mysql-password= --num-threads=16 --max-time=600 run

OLTP test statistics:

    queries performed:

        read:                            5777898

        write:                           2063535

        other:                           825414

        total:                           8666847

    transactions:                        412707 (687.83 per sec.)

    deadlocks:                           0      (0.00 per sec.)

    read/write requests:                 7841433 (13068.78 per sec.)

    other operations:                    825414 (1375.66 per sec.)

 

Test execution summary:

    total time:                          600.0128s

    total number of events:              412707

    total time taken by event execution: 9595.4495

    per-request statistics:

         min:                                  3.87ms

         avg:                                 23.25ms

         max:                               8699.18ms

         approx.  95 percentile:              44.69ms

 

Threads fairness:

    events (avg/stddev):           25794.1875/97.71

    execution time (avg/stddev):   599.7156/0.00

 

#使用16个线程开始测试,只读模式。

#sysbench  --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mysql-table-engine=innodb --oltp-table-size=10000000 --db-ps-mode=disable  --mysql-user=root --mysql-host=localhost --mysql-socket=/tmp/mysql.sock  --oltp-read-only --mysql-password= --num-threads=16 --max-time=600 run

OLTP test statistics:

    queries performed:

        read:                            3617138

        write:                           0

        other:                           516734

        total:                           4133872

    transactions:                        258367 (430.59 per sec.)

    deadlocks:                           0      (0.00 per sec.)

    read/write requests:                 3617138 (6028.33 per sec.)

    other operations:                    516734 (861.19 per sec.)

 

Test execution summary:

    total time:                          600.0233s

    total number of events:              258367

    total time taken by event execution: 9597.2735

    per-request statistics:

         min:                                  3.76ms

         avg:                                 37.15ms

         max:                                103.82ms

         approx.  95 percentile:              49.00ms

 

Threads fairness:

    events (avg/stddev):           16147.9375/20.32

    execution time (avg/stddev):   599.8296/0.01

 

#清理测试的残留信息

sysbench  --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mys

测试脚本

测试文件I/O的脚本

#!/bin/bash

#==============================================================================

#

#          FILE: sysbench_auto.sh

#

#         USAGE: ./sysbench_auto.sh

#

#   DESCRIPTION: This file is sysbench_auto.sh

#        AUTHOR: Kevin Lu (kevin), [email protected]

#  ORGANIZATION: cmcc

#       CREATED: 02/26/2014 17:35

#      REVISION: v1.0.1

#==============================================================================

for size in {8G,64G}

do

for mode in {seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}

do

for blksize in {4096,16384}

do

sysbench --test=fileio --file-num=64 --file-total-size=$size prepare

for threads in {1,4,8,16,32}

do

echo "=============testing $blksize in $threads threads"

echo PARAS $size $mode $threads $blksize > sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize

for i in {1,2,3}

do

sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode --max-time=180 --max-requests=100000 --num-threads=$threads --

init-rng=on --file-num=64 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksize run|tee -a sysbench-size-$size-mo

de-$mode-threads-$threads-blksz-$blksize 2>&1

done

done

sysbench --test=fileio --file-total-size=$size cleanup

done

done

done

 

猜你喜欢

转载自www.cnblogs.com/HByang/p/9131985.html