zoukankan      html  css  js  c++  java
  • sysbench 0.5 基准测试

    sysbench 介绍

    SysBench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。它主要包括以下几种方式的测试:

    1. cpu性能
    2. 磁盘io性能
    3. 调度程序性能
    4. 内存分配及传输速度
    5. POSIX线程性能
    6. 数据库性能(OLTP基准测试)

    目前sysbench主要支持 MySQL,pgsql,Oracle 这3种数据库。

    sysbench 安装

    默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数,
    sysbench默认安装在: /usr/local/bin/sysbench

    shell> tar -zxvf sysbench-0.5.tar.gz -C /db/tool/
    shell> cd /db/tool/sysbench-0.5
    shell> chmod +x autogen.sh
    
    shell> ./autogen.sh 
    automake 1.10.x (aclocal) wasn't found, exiting
    shell> yum install automake
    shell> ./autogen.sh 
    libtoolize 1.4+ wasn't found, exiting
    shell> yum install libtool
    
    shell> ./autogen.sh 
    ./autogen.sh 
    ./autogen.sh: running `aclocal -I m4' 
    ./autogen.sh: running `libtoolize --copy --force' 
    libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
    libtoolize: copying file `config/ltmain.sh'
    libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
    libtoolize: copying file `m4/libtool.m4'
    libtoolize: copying file `m4/ltoptions.m4'
    libtoolize: copying file `m4/ltsugar.m4'
    libtoolize: copying file `m4/ltversion.m4'
    libtoolize: copying file `m4/lt~obsolete.m4'
    ./autogen.sh: running `autoheader' 
    ./autogen.sh: running `automake -c --foreign --add-missing' 
    configure.ac:23: installing `config/compile'
    configure.ac:11: installing `config/config.guess'
    configure.ac:11: installing `config/config.sub'
    configure.ac:16: installing `config/install-sh'
    configure.ac:16: installing `config/missing'
    sysbench/Makefile.am: installing `config/depcomp'
    ./autogen.sh: running `autoconf' 
    Libtoolized with: libtoolize (GNU libtool) 2.2.6b
    Automade with: automake (GNU automake) 1.11.1
    Configured with: autoconf (GNU Autoconf) 2.63
    
    shell> ./configure --prefix=/db/sysbench --with-mysql-includes=/db/mysql/include --with-mysql-libs=/db/mysql/lib
    shell> make && make install
    
    测试安装
    shell> cp /db/sysbench/bin/sysbench /usr/local/bin/
    
    shell> sysbench --help
    sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: 
    No such file or directory
    问题原因:sysbench无法找到mysql的库文件,可能是环境变量LD_LIBRARY_PATH没有设置,设置后即可解决该问题: 
    添加export LD_LIBRARY_PATH=/db/mysql/lib即可

    sysbench 参数

    shell> sysbench --help
    Missing required command argument.
    Usage:
      sysbench [general-options]... --test= [test-options]... command
    
    General options:
      --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]
      --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown [off]
      --thread-stack-size=SIZE   size of stack per thread [64K]
      --tx-rate=N                target transaction rate (tps) [0]
      --tx-jitter=N              target transaction variation, in microseconds [0]
      --report-interval=N        periodically report intermediate statistics with a specified interval in seconds. 0 disables
     intermediate reports [0]
      --test=STRING              test to run
      --debug=[on|off]           print more debugging info [off]
      --validate=[on|off]        perform validation checks where possible [off]
      --help=[on|off]            print help and exit
      --version=[on|off]         print version and exit [off]
      --rand-init=[on|off]       initialize random number generator [off]
      --rand-type=STRING         random numbers distribution {uniform,gaussian,special} [special]
      --rand-spec-iter=N         number of iterations used for numbers generation [12]
      --rand-spec-pct=N          percentage of values to be treated as 'special' (for special distribution) [1]
      --rand-spec-res=N          percentage of 'special' values to use (for special distribution) [75]
      --rand-seed=N              seed for random number generator, ignored when 0 [0]
    
    Log options:
      --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [3]
    
      --percentile=N      percentile rank of query response times to count [95]
    
    Compiled-in tests:
      fileio - File I/O test
      cpu - CPU performance test
      memory - Memory functions speed test
      threads - Threads subsystem performance test
      mutex - Mutex performance test
    
    Commands: prepare run cleanup help version
    
    See 'sysbench --test= help' for a list of options for each test.

    CPU测试

    sysbench CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间

    shell> sysbench --test=cpu --cpu-max-prime=2000 run
    sysbench 0.5:  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
    
    
    Primer numbers limit: 2000
    
    Threads started!
    
    
    Test execution summary:
        total time:                          2.2452s
        total number of events:              10000
        total time taken by event execution: 2.2347s
        per-request statistics:
             min:                                  0.20ms
             avg:                                  0.22ms
             max:                                  3.35ms
             approx.  95 percentile:               0.27ms
    
    Threads fairness:
        events (avg/stddev):           10000.0000/0.00
        execution time (avg/stddev):   2.2347/0.00
    
    补充:
    查看CPU信息方法
    查看物理cpu个数
     grep "physical id" /proc/cpuinfo | sort -u | wc -l
    查看核心数量
     grep "core id" /proc/cpuinfo | sort -u | wc -l
    查看线程数量
     grep "processor" /proc/cpuinfo | sort -u | wc -l
    
    在sysbench的测试中,--num-threads取值为"线程数量"即可

    线程(thread)测试

    测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用

    shell> sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
    sysbench 0.5:  multi-threaded system evaluation benchmark
    
    Running the test with following options:
    Number of threads: 64
    Random number generator seed is 0 and will be ignored
    
    
    Threads started!
    
    
    Test execution summary:
        total time:                          1.9581s
        total number of events:              10000
        total time taken by event execution: 124.8938s
        per-request statistics:
             min:                                  0.05ms
             avg:                                 12.49ms
             max:                                151.15ms
             approx.  95 percentile:              50.83ms
    
    Threads fairness:
        events (avg/stddev):           156.2500/14.48
        execution time (avg/stddev):   1.9515/0.00

    文件IO性能测试

    • 生成需要的测试文件,文件总大小5G,16个并发线程。执行完后会在当前目录下生成一堆小文件。
    shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare
    • 执行测试,指定随机读写模式

    指定读写模式:

    1. seqwr 顺序写入
    2. seqrewr 顺序重写
    3. seqrd 顺序读取
    4. rndrd 随机读取
    5. rndwr 随机写入
    6. rndrw 混合随机读/写
    shell> sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw run
    sysbench 0.5:  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
    
    
    Threads started!
    
    Operations performed:  5999 reads, 4001 writes, 12800 Other = 22800 Total
    Read 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (9.2561Mb/sec)   ##吞吐量
      592.39 Requests/sec executed
    
    Test execution summary:
        total time:                          16.8808s
        total number of events:              10000
        total time taken by event execution: 176.1816s
        per-request statistics:
             min:                                  0.01ms
             avg:                                 17.62ms
             max:                                416.73ms
             approx.  95 percentile:             104.82ms
    
    Threads fairness:
        events (avg/stddev):           625.0000/62.39
        execution time (avg/stddev):   11.0114/0.67
    • 清除测试文件
    shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup

    互斥锁(Mutex)测试

    测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。

    shell> sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
    sysbench 0.5:  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
    
    
    Threads started!
    
    
    Test execution summary:
        total time:                          0.0135s
        total number of events:              16
        total time taken by event execution: 0.0411s
        per-request statistics:
             min:                                  0.70ms
             avg:                                  2.57ms
             max:                                  9.19ms
             approx.  95 percentile:               9.16ms
    
    Threads fairness:
        events (avg/stddev):           1.0000/0.00
        execution time (avg/stddev):   0.0026/0.00

    内存测试

    内存测试测试了内存的连续读写性能。

    shell> sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run
    sysbench 0.5:  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
    
    
    Threads started!
    
    Operations performed: 131072 (381158.38 ops/sec)
    
    1024.00 MB transferred (2977.80 MB/sec)       ##吞吐量
    
    
    Test execution summary:
        total time:                          0.3439s
        total number of events:              131072
        total time taken by event execution: 3.9915s
        per-request statistics:
             min:                                  0.00ms
             avg:                                  0.03ms
             max:                                 51.02ms
             approx.  95 percentile:               0.00ms  ##大约95%的时间分布
    
    Threads fairness:
        events (avg/stddev):           8192.0000/1166.77
        execution time (avg/stddev):   0.2495/0.02

    MySQL数据库测试

    sysbench 0.5通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,脚本使用方式基本类似。

    sysbench 0.5默认使用sbtest库,但是需要自己手工先创建好,也可以使用--mysql-db指定,其他非默认项指定选项:

    1. -mysql-host
    2. -mysql-port
    3. -mysql-socket
    4. -mysql-user
    5. -mysql-password
    6. -mysql-db
    7. -mysql-ssl
    • prepare
      生成表并插入数据,可使用parallel_prepare.lua脚本来并行准备数据。
    1. –db-driver 服务器类型 mysql | drizzle,默认为mysql
    2. –mysql-table-engine 表存数引擎
    3. –myisam-max-rows MyISAM表MAX_ROWS选项(用于大表)
    4. –oltp-table-count 生成表数量[sbtest1、sbtest2...]
    5. –oltp-table-size 生成表的行数
    6. –oltp-secondary ID列生成二级索引而不是主键
    7. –oltp-auto-inc 设置ID列是否自增 on | off,默认为on
    shell> cd /db/tool/sysbench-0.5/sysbench
    shell> sysbench --test=./tests/db/oltp.lua --mysql-table-engine=myisam --oltp-table-size=100000 --mysql-db=test
     --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle --mysql-socket=/tmp/mysql.sock prepare
    sysbench 0.5:  multi-threaded system evaluation benchmark
    
    Creating table 'sbtest1'...
    Inserting 100000 records into 'sbtest1'
    Creating table 'sbtest2'...
    Inserting 100000 records into 'sbtest2'
    Creating table 'sbtest3'...
    Inserting 100000 records into 'sbtest3'
    Creating table 'sbtest4'...
    Inserting 100000 records into 'sbtest4'
    Creating table 'sbtest5'...
    Inserting 100000 records into 'sbtest5'
    Creating table 'sbtest6'...
    Inserting 100000 records into 'sbtest6'
    Creating table 'sbtest7'...
    Inserting 100000 records into 'sbtest7'
    Creating table 'sbtest8'...
    Inserting 100000 records into 'sbtest8'
    Creating table 'sbtest9'...
    Inserting 100000 records into 'sbtest9'
    Creating table 'sbtest10'...
    Inserting 100000 records into 'sbtest10'
    
    也可使用parallel_prepare.lua脚本并行准备测试数据,线程数应该为运行表的倍数
    shell> sysbench --test=./tests/db/parallel_prepare.lua  --mysql-table-engine=myisam --oltp-table-size=100000 
     --num-threads=10 --mysql-db=test  --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle 
     --mysql-socket=/tmp/mysql.sock run
    
    sysbench 0.5:  multi-threaded system evaluation benchmark
    
    Running the test with following options:
    Number of threads: 10
    Random number generator seed is 0 and will be ignored
    
    
    Threads started!
    
    thread prepare8
    Creating table 'sbtest9'...
    thread prepare1
    Creating table 'sbtest2'...
    thread prepare0
    Creating table 'sbtest1'...
    thread prepare5
    Creating table 'sbtest6'...
    thread prepare3
    Creating table 'sbtest4'...
    thread prepare6
    Creating table 'sbtest7'...
    thread prepare9
    Creating table 'sbtest10'...
    thread prepare4
    Creating table 'sbtest5'...
    thread prepare2
    Creating table 'sbtest3'...
    thread prepare7
    Creating table 'sbtest8'...
    Inserting 100000 records into 'sbtest1'
    Inserting 100000 records into 'sbtest9'
    Inserting 100000 records into 'sbtest8'
    Inserting 100000 records into 'sbtest6'
    Inserting 100000 records into 'sbtest7'
    Inserting 100000 records into 'sbtest2'
    Inserting 100000 records into 'sbtest10'
    Inserting 100000 records into 'sbtest4'
    Inserting 100000 records into 'sbtest5'
    Inserting 100000 records into 'sbtest3'
    OLTP test statistics:
        queries performed:
            read:                            0
            write:                           380
            other:                           20
            total:                           400
        transactions:                        0      (0.00 per sec.)
        deadlocks:                           0      (0.00 per sec.)
        read/write requests:                 380    (32.82 per sec.)
        other operations:                    20     (1.73 per sec.)
    
    Test execution summary:
        total time:                          11.5785s
        total number of events:              10000
        total time taken by event execution: 0.1422s
        per-request statistics:
             min:                                  0.00ms
             avg:                                  0.01ms
             max:                                 19.55ms
             approx.  95 percentile:               0.00ms
    http://ww3.sinaimg.cn/bmiddle/671c4d8egw1enjimkujv2g20b40b4b29.gif
    Threads fairness:
        events (avg/stddev):           1000.0000/2912.74
        execution time (avg/stddev):   0.0142/0.04
    • run
    1. –oltp-tables-count
    2. –oltp-read-only 仅执行SELECT测试 on | off,默认为off
    3. –oltp-dist-type 随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布)
    4. –oltp-dist-pct 特殊分布的百分比值
    5. –oltp-dist-res 特殊分布的百分比
    6. –oltp-point-selects 单个事务中指定的selec查询个数
    7. –oltp-range-size 范围查询的范围大小,该值应比oltp-table-size小
    8. –oltp-simple-ranges 单个事务中指定的简单范围查询个数
    9. –oltp-sum-ranges 单个事务中指定的SUM范围查询个数
    10. –oltp-order-ranges 单个事务中指定的ORDER范围查询个数
    11. –oltp-distinct-ranges 单个事务中指定的DISTINCT范围查询个数
    12. –oltp-index-updates 单个事务中指定的使用索引更新的个数
    13. –oltp-non-index-updates 单个事务中指定的不使用索引更新的个数
    shell> sysbench --test=./tests/db/oltp.lua --num_threads=10  --oltp-table-size=100000 
    --mysql-db=test --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle  run
    sysbench 0.5:  multi-threaded system evaluation benchmark
    
    Running the test with following options:
    Number of threads: 10
    Random number generator seed is 0 and will be ignored
    
    
    Threads started!
    
    OLTP test statistics:
        queries performed:
            read:                            140028  -- 读总数
            write:                           40008   -- 写总数
            other:                           20004   -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
            total:                           200040  -- 全部总数
        transactions:                        10002  (234.44 per sec.)  -- 总事务数(每秒事务数)
        deadlocks:                           0      (0.00 per sec.)    -- 发生死锁总数
        read/write requests:                 180036 (4219.99 per sec.) -- 读写总数(每秒读写次数)
        other operations:                    20004  (468.89 per sec.)  -- 其他操作总数(每秒其他操作次数)
    
    Test execution summary:
        total time:                          42.6626s  -- 总耗时
        total number of events:              10002     -- 共发生多少事务数
        total time taken by event execution: 426.3020s -- 所有事务耗时相加(不考虑并行因素)
        per-request statistics:
             min:                                  5.36ms   -- 最小耗时
             avg:                                 42.62ms   -- 平均耗时
             max:                                183.44ms   -- 最长耗时
             approx.  95 percentile:              59.81ms   -- 超过99%平均耗时
    
    Threads fairness:
        events (avg/stddev):           1000.2000/23.87
        execution time (avg/stddev):   42.6302/0.01
    • clearnup
    shell> sysbench --test=./tests/db/oltp.lua --oltp-table-size=100000 --mysql-db=test --mysql-user=root 
    --oltp-tables-count=10 --mysql-password=oracle  cleanup
    sysbench 0.5:  multi-threaded system evaluation benchmark
    
    Dropping table 'sbtest1'...
    Dropping table 'sbtest2'...
    Dropping table 'sbtest3'...
    Dropping table 'sbtest4'...
    Dropping table 'sbtest5'...
    Dropping table 'sbtest6'...
    Dropping table 'sbtest7'...
    Dropping table 'sbtest8'...
    Dropping table 'sbtest9'...
    Dropping table 'sbtest10'...
     
    可以对数据库进行调优后,再使用sysbench对OLTP进行测试,看看TPS是不是会有所提高。
    注意:sysbench的测试只是基准测试,并不能代表实际企业环境下的性能指标。
  • 相关阅读:
    思科模拟器——常用命令
    思科模拟器——允许远程telnet连接控制路由器/交换机
    思科模拟器——使用路由器分割局域网
    如何将centos7作为DNS服务器
    Centos7设置grub密码保护
    curl提示不支持https协议解决方法
    Kettle入门--作业和转换的使用
    oracle命令导入SQL脚本
    centos7 部署elasticsearch
    Nginx通过Keepalived实现高可用
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/7358693.html
Copyright © 2011-2022 走看看