zoukankan      html  css  js  c++  java
  • sysbench测试工具

    sysbench简介

         Sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。它主要包括以下几种方式的测试:cpu性能,磁盘io性能,线程调度性能,内存分配及传输速度和数据库性能。由于本人是dba,因此重点关注sysbench测试数据库的场景。目前sysbench支持mysql,postgreSQL,oracle三种数据源。

    下载&安装

    1)  下载

    通过http://download.csdn.net/download/jungeshidai/8854157页面下载sysbench0.5版本

    2)  编译安装 

    tar -zxvf sysbench-0.5.tar.gz
    cd sysbench-0.5
    ./autogen.sh
    ./configure
    ./make
    ./make install

    3)  可能遇到的问题

       a) lua脚本,因为sysbench0.5的测试用例改为lua,若有童鞋使用0.5版本,执行命令时仍然采用老的方式,--test=oltp,就会出现报错

        “PANIC: unprotected error in call to Lua API (cannot open oltp: No such file or directory)”,因此注意将--test=oltp改为./tests/db/oltp.lua即可。

       b) 运行oltp测试时,默认会在sbtest库里面建表测试,但是库需要自己预先建立好,否则就会出现连不上database的错误,当然,也可以通过参数--mysql-db指定。

    测试过程

    测试主要包括准备数据阶段,测试阶段和清理阶段。

    1)  准备阶段

    sysbench --test=./tests/db/oltp.lua --mysql-table-engine=innodb --oltp-table-size=100000 --mysql-socket=/u01/my3306/run/mysql.sock --mysql-user=chuck --mysql-host=localhost --mysql-password=chuck --num-threads=20 prepare

    2)  测试阶段

    sysbench --test=./tests/db/oltp.lua --mysql-table-engine=innodb --num_threads=10  --oltp-table-size=100000 --mysql-db=test
    --mysql-user=chuck --oltp-tables-count=10 --mysql-password=chuck  run

    3)  清理阶段

    sysbench --test=./tests/db/select.lua --mysql-table-engine=innodb --num_threads=10 --oltp-table-size=100000 --mysql-db=test --mysql-user=chuck --oltp-tables-count=10 --mysql-password=chuck cleanup

    重要参数

    --test=STRING
    指定测试用例,sysbench0.5所有测试用例采用lua脚本编写,用户可以根据需求写符合自己测试的脚本,因此非常灵活。比如:--test=./tests/db/select.lua

    --max-requests=N,设置请求的数目,默认值是10000

    --max-time=N,设置执行的时间,默认是0,即没有限制
    这两个参数可以配合起来使用,默认值表示,执行完10000个请求,不受时间限制。因为请求可以多种多样,对于不同的lua脚本,对应的就是不同的请求,比如
    insert.lua,delete.lua,select.lua等。当然你也可以编辑自己的lua脚本,封装成为一个event。因此,对于不同类型的测试用例,执行时间会相差很大。对于运行时间很快的测试用例,可以增大max-requests的值,对于运行很慢的测试用例,可以通过设置max-time来限制运行时常。

    --report-interval=N,设置打印的时间间隔,默认值是0,设置执行的时长,以秒为单位对于很长时间的测试用例,为了得到实时的测试信息,可以设置该参数,否则,只有一直干等,运行结束后才能看到测试报告。

    --percentile=N,设置采样比例,默认是95%

    --num-threads=N,设置并发的线程数目

    执行结果解读

    这里以oltp.lua测试用例的测试结果来简单说明下。

    sysbench --test=./tests/db/oltp.lua --num_threads=10  --oltp-table-size=100000 --mysql-db=test --mysql-user=chuck --oltp-tables-count=10 --mysql-password=chuck --max-requests=100000 --report-interval=5 --percentile=95  run

    1)  实时信息

    每5s采集一次实时信息,tps表示事务数目,writes/reads分别表示平均每秒写和读的次数

    [   5s] threads: 10, tps: 31.80, reads/s: 460.79, writes/s: 128.00  

    [  10s] threads: 10, tps: 35.40, reads/s: 502.00, writes/s: 143.00

    [  15s] threads: 10, tps: 31.20, reads/s: 438.20, writes/s: 124.20

    [  20s] threads: 10, tps: 33.00, reads/s: 463.60, writes/s: 130.40

    [  25s] threads: 10, tps: 33.60, reads/s: 462.40, writes/s: 134.40

    [  30s] threads: 10, tps: 34.20, reads/s: 484.80, writes/s: 137.20

    [  35s] threads: 10, tps: 31.00, reads/s: 438.20, writes/s: 124.40

    [  40s] threads: 10, tps: 32.20, reads/s: 445.40, writes/s: 128.60

    2) 汇总信息

    OLTP test statistics:
        queries performed:
            read:                            140000
            write:                           40000
            other:                           20000
            total:                            200000
        transactions:                     10000  (32.89 per sec.)  //总共执行了10000个事务
        deadlocks:                           0      (0.00 per sec.)
        read/write requests:           180000 (592.04 per sec.) //读写请求有180000,一个事务包含多个读写请求
        other operations:                20000  (65.78 per sec.)

    Test execution summary:
        total time:                          304.0326s  //总共运行了5分钟
        total number of events:        10000
        total time taken by event execution: 3039.9491s
        per-request statistics:
             min:                                 27.73ms
             avg:                                303.99ms
             max:                               1940.30ms
             approx.  95 percentile:      635.58ms   //95%的平均耗时为635ms,这里对统计值有点疑问,95%的是635ms,而平均值是300ms。

    Threads fairness:
        events (avg/stddev):              1000.0000/14.47
        execution time (avg/stddev):   303.9949/0.02
         

    参考文档

    http://www.tuicool.com/articles/iQFF3i

     

  • 相关阅读:
    [LeetCode]130 Surrounded Regions(DFS)
    [LeetCode]233 Number of Digit One(数位DP)
    POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)
    POJ 2528.Mayor's posters-线段树(成段替换、离散数据、简单hash)
    POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)
    HDU 1698.Just a Hook-线段树(成段替换、输出总和tree[1])
    POJ 2886.Who Gets the Most Candies? -线段树(单点更新、类约瑟夫问题)
    计蒜客 28437.Big brother said the calculation-线段树+二分-当前第k个位置的数 ( ACM训练联盟周赛 M)
    HDU 5649.DZY Loves Sorting-线段树+二分-当前第k个位置的数
    计蒜客 28449.算个欧拉函数给大家助助兴-大数的因子个数 (HDU5649.DZY Loves Sorting) ( ACM训练联盟周赛 G)
  • 原文地址:https://www.cnblogs.com/cchust/p/4723672.html
Copyright © 2011-2022 走看看