zoukankan      html  css  js  c++  java
  • 使用sysbench 对mysql进行性能测试

    使用sysbench 对mysql进行性能测试

    sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行。

    1. 安装

    操作系统:Centos 6.8 x86-64

    安装依赖

    yum install m4 autoconf automake libtool

    安装sysbench

    wget http://olvimidkv.bkt.clouddn.com/sysbench-0.4.12-1.1.tgz
    tar -xf sysbench-0.4.12-1.1.tgz
    cd sysbench-0.4.12-1.1
    ./autogen.sh
    编译
    ./configure --with-mysql-includes=/home/xiaohe/mysql-3306/include/ --with-mysql-libs=/home/xiaohe/mysql-3306/lib/
    # 默认安装只支持MySQL,如果要支持pgsql/oracle 就需要在编译的时候加上--with-pgsql 或 --with-oracle
    安装
    make && make install
    
    因为是指定路径编译安装的所以会报下面的错误
    
    sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
    
    说明sysbench无法找到mysql的库文件,因此需要指定mysqllib的路径
    
    export LD_LIBRARY_PATH=/home/xiaohe/mysql-3306/lib/
    最好写到/etc/profile里面,这样就不会每次登陆都要设置了
    
    sysbench --help  如果不报错,就说明成功了。
    
    按照文档一般不会出错,要是还是出错,请Google。
    

    参数说明

    好多英文,自己体会,用的时候仔细看看。

    [root@XH-TEST-01 ~]# sysbench --help
    Usage: 用法:
      sysbench [general-options]... --test=<test-name> [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]
      --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. []
      --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,pareto} [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]
      --rand-pareto-h=N           parameter h for pareto distibution [0.2]
    
    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   磁盘IO
      cpu - CPU performance test   CPU 
      memory - Memory functions speed test  内存分配及速度
      threads - Threads subsystem performance test  多线程性能
      mutex - Mutex performance test   调度程序性能
    

    还有具体的项的帮助,如下,具体的自行查看。

    sysbench --test=fileio help
    sysbench --test=cup help
    sysbench  --test=memory help
    sysbench  --test=threads help
    sysbench  --test=mutex help 
    sysbench --test=oltp help 
    

    测试实例

    1. 磁盘测试

    创建初始化fileio文件
    sysbench --test=fileio --file-num=16 --file-total-size=2G prepare
    

    开始测试

    接下来开始对这些文件进行测试,使用16个线程随机读进行测试结果如下:

    sysbench --test=fileio --file-total-size=2G --file-test-mode=rndrd --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
    

    随机读写每秒2.3817Mb IOPS 每秒152.43 说明很糟糕。

    仿真环境的数据如下

    好了不少,但还是比较慢的。

    测试完成之后记得删除测试文件。
    sysbench --test=fileio --file-num=16 --file-total-size=2G cleanup
    

    如果需要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,并且还可能需要测试不同的线程和不同的文件块下磁盘的性能表现,这时,可以使用如下脚本达到测试目的。

    #!/bin/bash
     
    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
    

    内存测试

    sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
    
    ![](media/14879298422832/14881811382311.jpg)
    

    内存差距一般不大,测试io意义更大些。

    3.对MySQL事务型OLTP的测试 以这个为例,其它的换对应的lua脚本即可。

    对于mysql的OLTP测试,和file一样,同样需要经历prepare,run,cleanup三个阶段。prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为
    sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:

    常用参数简单说明:      
       --report-interval=10:每隔多久打印一次统计信息,单位秒,0.5版本新增  
       --rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同。  
       --rand-type=special:数据分布模式,special表示存在热点数据,uniform表示非热点数据模式
       --mysql-table-engine=xxx:表的存储引擎类型,innodb、myisam、tokudb这些都可以
    
    prepare准备阶段

    初始化

    sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  --num-threads=16 --mysql-table-engine=InnoDB  --rand-init=on   --mysql-db=test prepare
    

    run运行测试

    压力测试

    sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua  --oltp_tables_count=10 --oltp-table-size=100000 --oltp-dist-type=uniform   --report-interval=10 --rand-init=on  --mysql-table-engine=InnoDB  --mysql-db=test --max-time=3600 --max-requests=0 --num-threads=16 --thread-stack-size=256 --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  run > result.log
    

    参数说明:
    --max-time=3600 指定测试时长为1小时
    --mysql-db=test 指定测试的数据库名

    清理
    sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua  --oltp_tables_count=10 --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  --mysql-table-engine=InnoDB --mysql-db=test cleanup
    

  • 相关阅读:
    在 Students 的 Index 页面增加列标题链接(排序),分页,过滤和分组功能
    Contoso 大学
    如何搭建MVC + EF 框架
    EF与手写Model的区别以及联系
    報錯:One or more validation errors were detected during model generation:System.Data.Edm.EdmEntityType: : EntityType 'Movie' has no key
    Oracle四舍五入,向上取整,向下取整
    datagrid中设置编辑,删除列是否可以访问
    datagrid中设置编辑,删除列是否可以访问
    C#实现打印
    C#中rpt的数据类型和Oracle中数据类型的匹配
  • 原文地址:https://www.cnblogs.com/colder219/p/6483976.html
Copyright © 2011-2022 走看看