码迷,mamicode.com
首页 > 其他好文 > 详细

sysbench 压测 详解

时间:2018-07-10 21:25:44      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:events   切换   commit   file   事务   fda   execution   nokey   report   

下载sysbench(mysql官网就有)
解压,进入解压以后的目录
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make && make install
export LD_LIBRARY_PATH=/usr/local/mysql/lib

开始进行测试
通用配置
接下来我们来分别看一下各个模式的相关参数、测试方法和结果分析。
sysbench的基本命令格式为:
sysbench –test=< test-name> [options]… < command>
主要分为三个部分:

1、–test=< test-name>
这部分是指定测试类型,基本类型有fileio,cpu,memory,threads,mutex,oltp(或者指定lua脚本)

2、[options]…
这部分包括测试需要的各种选项,有全局的也有每个测试模式自由的选项
(每个测试模式的选项可以用./sysbench –test=< test-name> help来获取)

3、< command>
控制命令,总共有五个
prepare #准备测试,主要是生成测试数据
run #执行测试,根据选项限制来执行测试
cleanup #清除准备阶段生成的测试数据
help #获取帮助文档
version #获取版本信息

几个重要的全局参数:
–num-threads=N number of threads to use [1] #测试时使用的线程数
–max-requests=N limit for total number of requests [10000] #测试过程最多执行多少次请求
–max-time=N limit for total execution time in seconds [0] #测试过程总共执行多长时间(和–max-requests效果同样,但是两个同时限定的时候谁优先还没有测试)
–report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] #每隔多少秒输出测试概况(这个过程你可以观察到mysql redolog的切换情况)
–db-driver=STRING specifies database driver to use (‘help’ to get list of available drivers) #指定需求测试的数据库类型,默认是mysql
#mysql链接选项
–mysql-host=[LIST,…] MySQL server host [localhost] #mysql主机地址
–mysql-port=N MySQL server port [3306] #mysql端口
–mysql-socket=[LIST,…] MySQL socket #mysql socket文件位置,指定这个之后 其他的链接选项均可以不指定
–mysql-user=STRING MySQL user [sbtest] #用来测试的mysql用户名
–mysql-password=STRING MySQL password [] #密码
–mysql-db=STRING MySQL database name [sbtest] #测试数据库名 默认sbtest

1、测试磁盘IO性能

参数详解: 
–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。
1)生成测试文件
sysbench --test=fileio --file-num=10 --file-total-size=5G prepare
2)测试
sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=10 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
3)结果如下
sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored

Extra file open flags: 4000
10 files, 512Mb each
5Gb total file size
Block size 16Kb
Number of random requests for random IO: 100000000
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!

Time limit exceeded, exiting...
(last message repeated 15 times)
Done.

Operations performed:  17981 reads, 11990 writes, 0 Other = 29971 Total
Read 280.95Mb  Written 187.34Mb  Total transferred 468.3Mb  (2.6012Mb/sec)
  166.48 Requests/sec executed

General statistics:
    total time:                          180.0298s
    total number of events:              29971
    total time taken by event execution: 2880.3206
    response time:
         min:                                  0.38ms
         avg:                                 96.10ms
         max:                                390.42ms
         approx.  95 percentile:             209.91ms

Threads fairness:
    events (avg/stddev):           1873.1875/11.51
    execution time (avg/stddev):   180.0200/0.01

        ##注意:主要看这里
        Read 280.95Mb  Written 187.34Mb  Total transferred 468.3Mb  (2.6012Mb/sec)  166.48 Requests/sec executed

        大概是在180秒里面总共随机读取280.95MB ,写入187.24MB ,平均每秒随机读写的效率时2.6012MB ,IOPS为166.48 Requests/sec 

4)清楚测试数据
    sysbench --test=fileio --file-num=10 --file-total-size=5G cleanup

2、cpu测试
参数详解:
–cpu-max-prime=N 用来选项指定最大的素数,具体参数可以根据CPU的性能来设置,默认为10000

sysbench --test=cpu --cpu-max-prime=20000 run

测试结果
    sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 1
    Random number generator seed is 0 and will be ignored

    Doing CPU performance benchmark

    Primer numbers limit: 20000

    Threads started!
    Done.

    General statistics:
        total time:                          20.8126s
        total number of events:              10000
        total time taken by event execution: 20.8006
        response time:
             min:                                  1.91ms
             avg:                                  2.08ms
             max:                                 13.94ms
             approx.  95 percentile:               2.71ms

    Threads fairness:
        events (avg/stddev):           10000.0000/0.00
        execution time (avg/stddev):   20.8006/0.00

       ##注意:测试的总时间(total time)即可(越小越忧)

3、内存分配及传输速度(测试了内存的连续读写性能)
参数详解:
–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

sysbench --test=memory --memory-block-size=8K --memory-total-size=1G  --num-threads=16 run

结果:
    sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 16
    Random number generator seed is 0 and will be ignored

    Doing memory operations speed test
    Memory block size: 8K

    Memory transfer size: 1024M

    Memory operations type: write
    Memory scope type: global
    Threads started!
    Done.

    Operations performed: 131072 (1223663.93 ops/sec)

    1024.00 MB transferred (9559.87 MB/sec)

    General statistics:
        total time:                          0.1071s
        total number of events:              131072
        total time taken by event execution: 0.3210
        response time:
             min:                                  0.00ms
             avg:                                  0.00ms
             max:                                 96.20ms
             approx.  95 percentile:               0.00ms

    Threads fairness:
        events (avg/stddev):           8192.0000/7510.93
        execution time (avg/stddev):   0.0201/0.03

4、oltp-数据库性能测试
参数详解:
–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

  1)创建测试用的数据
    sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare
  2)开始测试
    sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=off --max-requests=0 --num-threads=8 run
  3)结果如下
        sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

        No DB drivers specified, using mysql
        Running the test with following options:
        Number of threads: 8
        Random number generator seed is 0 and will be ignored

        Doing OLTP test.
        Running mixed OLTP test
        Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
        Using "BEGIN" for starting transactions
        Using auto_inc on the id column
        Using 1 test tables
        Threads started!
        Time limit exceeded, exiting...
        (last message repeated 7 times)
        Done.

        OLTP test statistics:
            queries performed:
                read:                            263046
                write:                           93934
                other:                           37574
                total:                           394554
            transactions:                        18785  (313.05 per sec.)
            deadlocks:                           4      (0.07 per sec.)
            read/write requests:                 356980 (5948.98 per sec.)
            other operations:                    37574  (626.16 per sec.)

        General statistics:
            total time:                          60.0069s
            total number of events:              18785
            total time taken by event execution: 479.9184
            response time:
                 min:                                  2.23ms
                 avg:                                 25.55ms
                 max:                               1696.98ms
                 approx.  95 percentile:              54.14ms

        Threads fairness:
            events (avg/stddev):           2348.1250/6.21
            execution time (avg/stddev):   59.9898/0.00

##主要注意这几个参数 transactions: 18785 (313.05 per sec.)
read/write requests: 356980 (5948.98 per sec.)
other operations: 37574 (626.16 per sec.)

4)清除数据
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=off --max-requests=0 --num-threads=8 cleanup

sysbench 压测 详解

标签:events   切换   commit   file   事务   fda   execution   nokey   report   

原文地址:http://blog.51cto.com/13214087/2140038

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!