zoukankan      html  css  js  c++  java
  • sysbench基准测试工具使用

    1、源码编译安装

    源码下载地址(目前有0.4/0.5/1.0三个分支版本):https://github.com/akopytov/sysbench

    编译安装:

    unzip sysbench-1.0.zip
    //进入目录,配置编译安装
    ./autogen.sh
    ./configure --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/ --prefix=/usr/local/sysbench/v1.0
    make
    make install
    //配置环境变量
    //...

    可能遇到的问题

    编译安装完成以后,执行sysbench命令,会报如下错误:

    sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

    问题原因,没有正确配置环境变量LD_LIBRARY_PATH,执行如下命令(我的MySQL采用源码安装方式,目录在/usr/local/mysql,所以头文件与库文件都在该目录下):

    export LD_LIBRARY_PATH=/usr/local/mysql/lib/

    2、执行sysbench命令,打印出帮助信息如下:

    Missing required command argument.
    Usage:
    sysbench --test=<test-name> [options]... <command>

    Commands: prepare run cleanup help version     //Usage中的<command>部分,分别表示“准备”、“运行”、“清理”、“帮助”、“版本”

    General options:           //通用选项,用于设置线程数量,请求数目等多种测试属性
    --num-threads=N number of threads to use [1]
    --max-requests=N limit for total number of requests [10000]

    //略...

    General database options:      //通用的数据库选项,sysbench支持MySQL、Oracle等多种数据库测试

    --db-driver=STRING specifies database driver to use ('help' to get list of available drivers)  指定测试用的数据库驱动
    --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
    --db-debug=[on|off] print database-specific debug information [off]  数据库调试信息是否打开

    Compiled-in database drivers:    //内建的数据库驱动,对于MySQL数据库测试直接使用内建驱动就可以了
    mysql - MySQL driver

    mysql options:           //针对MySQL数据库测试的一些选项
    --mysql-host=[LIST,...] MySQL server host [localhost] 主机IP地址
    --mysql-port=[LIST,...] MySQL server port [3306] 主机端口号
    --mysql-socket=[LIST,...] MySQL socket 采用的socket
    --mysql-user=STRING MySQL user [sbtest] 用户名
    --mysql-password=STRING MySQL password [] 密码
    --mysql-db=STRING MySQL database name [sbtest] 测试目标数据库

    //略...

    Compiled-in tests: //内建的测试类型,如下5中测试直接在“--test=...”后面指定就可以了,如果内建测试不能满足需求可以采用lua脚本自定义测试
    fileio - File I/O test  IO性能测试
    cpu - CPU performance test  CPU性能测试
    memory - Memory functions speed test  内存连续读写性能测试
    threads - Threads subsystem performance test  线程调度器性能测试
    mutex - Mutex performance test  互斥锁性能测试

    3、内建测试1:fileio测试

    ①、准备测试数据集,使用prepare命令

    [lj95801@localhost sysbench]$ sysbench --test=fileio --file-total-size=5G prepare 

    --test=fileio  表示测试类型为内建的fileio测试

    --test-total-size=5G  表示准备测试数据集为50G大小

    prepare    命令准备测试数据集

    输出结果如下:

    sysbench 1.0: multi-threaded system evaluation benchmark

    128 files, 40960Kb each, 5120Mb total
    Creating files for the test...
    Extra file open flags: 0
    Creating file test_file.0
    Creating file test_file.1
    Creating file test_file.2

    //...

    从打印可以看出,程序会自动生成128个文件,每个文件4MB大小。

    ②、使用help命令,查看fileio测试的帮助文档:

    [luojun@localhost sysbench]$ sysbench --test=fileio help

    sysbench 1.0: multi-threaded system evaluation benchmark

    fileio options:   //可用的选项
    --file-num=N number of files to create [128]   //文件数量
    --file-block-size=N block size to use in all IO operations [16384]  //文件块大小设定
    --file-total-size=SIZE total size of files to create [2G]  //文件总大小
    --file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}  //测试模式
    --file-io-mode=STRING file operations mode {sync,async,mmap} [sync]  //io模式,“同步”、“异步”
    --file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
    --file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]  //fsync()方法调用频率
    --file-fsync-all=[on|off] do fsync() after each write operation [off]  //每一次写操作都进行fsync()同步,默认为off
    --file-fsync-end=[on|off] do fsync() at the end of test [on]  //在测试结束之前调用fsync()同步方法
    --file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
    --file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
    --file-rw-ratio=N reads/writes ratio for combined test [1.5]  //读写比率设定

    有一个重要的测试选项:--file-test-mode=STRING。其可用的选项为:

    seqwr:顺序写

    seqrewr:顺序重写

    seqrd:顺序读

    rndrd:随机读取

    rndwr:随机写入

    rndrw:混合随机读/写

    ③、作混合随机读写测试:

    [luojun@localhost sysbench]$ sysbench --test=fileio --file-test-mode=rndrw --file-total-size=5G --file-rw-ratio=2 run 

    选项解释:

    --test-fileio:测试类型为IO测试

    --file-total-size=5G:测试文件总大小为5G

    --file-test-mode=rndrw:文件IO测试模式为随机混合读写方式

    --file-rw-ratio=2:读写次数比率为2

    ④、分析打印结果

    sysbench 1.0:  multi-threaded system evaluation benchmark
    
    Running the test with following options:
    Number of threads: 1    //测试线程数
    Initializing random number generator from current time
    
    //测试属性设定,可以通过选项控制
    Extra file open flags: 0
    128 files, 40MiB each
    5GiB total file size
    Block size 16KiB
    Number of IO requests: 10000
    Read/Write ratio for combined random IO test: 2.00
    Periodic FSYNC enabled, calling fsync() each 100 requests.
    Calling fsync() at the end of test, Enabled.
    Using synchronous I/O mode
    Doing random r/w test
    Initializing worker threads...
    
    Threads started!
    
    //测试过程中文件操作情况
    File operations:
        reads/s:                      95.45  //每秒钟读请求数
        writes/s:                     47.72  //每秒钟写请求数
        fsyncs/s:                     183.25  //没表中同步次数
    
    //吞吐率
    Throughput:
        read, MiB/s:                  1.49  //读,1.49MB每秒
        written, MiB/s:               0.75  //写,0.75MB每秒
    
    //统计数据
    General statistics:
        total time:                          69.8488s    //测试总时长
        total number of events:              10000     //事件数量
        total time taken by event execution: 39.6674s   //事件执行事件
        response time: //事件响应事件统计
             min:                                  0.02ms   //最短
             avg:                                  3.97ms   //平均
             max:                                 27.70ms   //最长
             approx.  95 percentile:              11.77ms   //95%以上事件响应时长
    
    Threads fairness:  //线程公平性统计信息
        events (avg/stddev):           10000.0000/0.00
        execution time (avg/stddev):   39.6674/0.00

    与文件IO性能评价密切相关的指标有:每秒钟请求数、吞吐量、95%以上事件响应时间。

    ⑤、清除测试数据集

    [luojun@localhost sysbench]$ sysbench --test=fileio --file-total-size=5G cleanup

     参考文章:

    http://beagoodboy.iteye.com/blog/1280907

    《高性能MySQL》第三版

  • 相关阅读:
    visual studio 目录
    CMake教程小结
    CMake教程
    blender坐标系梳理
    Blender3d obj坐标转换示意图
    行列式的向量形式
    高等代数 第一章 行列式
    C++ Union实验
    git 分支合并学习实验
    C++使用memset注意事项
  • 原文地址:https://www.cnblogs.com/lj95801/p/5942841.html
Copyright © 2011-2022 走看看