• sysbench相关


      Sysbench工具是集系统测试和数据库测试一体的测试工具,但是传统的sysbench在数据库测试方面,没有遵循TPC-C测试模型,仅仅支持单个表的数据。而在实际的业务场景中,业务逻辑复杂的多。开源的优势就是,会有很多人参与进来,共同完善。Sysbench目前支持多个表的压测,并且通过自定义lua业务测试模型,使得测试更符合业务场景。

      sysbench支持以下几种测试模式:

    1、CPU运算性能
    2、磁盘IO性能
    3、调度程序性能
    4、内存分配及传输速度
    5、POSIX线程性能
    6、数据库性能(OLTP基准测试)
        * file I/O performance
        * scheduler performance
        * memory allocation and transfer speed
        * POSIX threads implementation performance
        * database server performance (OLTP benchmark)

    目前sysbench主要支持 mysql,drizzle,pgsql,oracle 等几种数据库。

    一、编译安装          http://github.com/akopytov/sysbench

    由于sysbench多表压测的源码使用bazaar进行管理,因此需要首先安装bazaar工具,才能获取源码。

    1、安装bazaar工具

    yum install bzr

    2、获取源码

    bzr branch lp:sysbench

    3、编译安装

    cd sysbench/ ; ./autogen.sh

    ./configure  --with-mysql-includes=/usr/local/mysql/include  --with-mysql-libs=/usr/local/mysql/lib

    make & make install  

    二、OLTP测试

      Sysbench通过调用parallel_prepare.lua脚本,进行并行数据准备。数据准备就绪后,调用oltp.lua脚本进行压力测试。有大量的测试参数,可以指定不同类型的操作比例,从而控制业务模型。参数可以参考说明文档,不在赘述。

    常用命令参数:

    /usr/local/sysbench-0.5/bin/sysbench 

         --mysql-host=test.mysql.rds.aliyuncs.com           #数据库host

         --mysql-port=3306                                              #数据库端口

         --mysql-user=your_username                             #数据库用户名

         --mysql-password=your_password                      #数据库密码

         --mysql-db=your_db_for_test                              #数据库名

         --oltp-tables-count=10                        #模拟的表的个数,规格越高该值越大

         --oltp-table-size=6000000                  #模拟的每张表的行数,规格越高该值越大

         --num-threads=50                              #模拟的并发数量,规格越高该值越大

         --max-requests=100000000               #最大请求次数

         --max-time=20                           #最大测试时间(与--max-requests只要有一个超过,则退出)

         --report-interval=1                     #每1秒打印一次当前的QPS等值

         --test=/tmp/sysbench-0.5/sysbench/tests/db/oltp.lua    #选用的测试脚本(lua),此脚本可以从sysbench-0.5源代码文件目录下找

         [prepare | run | cleanup]           #prepare准备数据,run执行测试,cleanup清理数据

    oltp options:
    –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 时,
    要自己先创建数据库 sbtest    否则提示找不到数据库,也可以用参数 --mysql-db 来指定使用其他数据库
    –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、数据准备

    > create databases sbtest;

    ./sysbench --test=tests/db/parallel_prepare.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=test --mysql-password=test --mysql-table-engine=innodb --oltp-table-size=100 --oltp-tables-count=32 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20  --mysql-host=127.0.0.1 --mysql-port=3306 prepare

    2、测试

    ./sysbench --test=tests/db/oltp.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=test --mysql-password=test --mysql-table-engine=innodb --oltp-table-size=100 --oltp-tables-count=32 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20  --mysql-host=127.0.0.1 --mysql-port=3306 run

      Sysbench还可以测试系统资源的性能,测试过程中,往往会首先通过sysbench测试系统的IO、内存、线程并发等性能。而MySQL的测试由于不是统一的测试模型,因此测试的结果会根据测试方法的不同,表现出较大的差异。

    -------------------------------------------------------------------------------------------------------

    查看相应的参数帮助信息: # sysbench --test=memory  help

    一、CPU测试

    sysbench采用寻找最大素数的方式来测试CPU的性能

    sysbench --test=cpu  --num-threads=`grep "processor" /proc/cpuinfo |wc -l` --cpu-max-prime=2000 run

    在sysbench的测试中,--num-threads 取值为"线程数量"即可,再大的值没有什么意义,对测试结果也没有什么影响

    sysbench 0.4.12:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 1

    Doing CPU performance benchmark

    Threads started!
    WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000
    WARNING: Percentile statistics will be inaccurate
    Done.

    Maximum prime number checked in CPU test: 2000

    Test execution summary:
        total time:                          1.5034s
        total number of events:              10000
        total time taken by event execution: 1.4998
        per-request statistics:
             min:                                  0.00ms
             avg:                                  0.15ms
             max:                                  0.57ms
             approx.  95 percentile:               0.31ms

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

    从total time: 一行可以看出在求得2000以内的最大素数时使用了1.5034s

    二、内存测试

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

    #sysbench --test=memory --memory-block-size=8k --memory-total-size=2G --num-threads=4 run

    上面语句指定了整个测试过程中,传输2G的数据量,每个block的大小为8k。和CPU测试一样,只需关心 total time 即可。

    三、文件(磁盘)IO性能测试

    使用fileio测试,首先得生成文件,然后对文件或读或写,测试fileio性能

    测试类型 test mode 如下:

    seqwr     顺序写入

    seqrewr  顺序重写

    seqrd  顺序读取

    rndrd  随机读取

    rndwr  随机写入

    rndrw  混合随机读/写

    #sysbench --test=fileio --num-threads=16 --file-total-size=3G  prepare    会生成一些文件

    #sysbench --test=fileio --num-threads=16 --file-total-size=3G --max-time=300 --file-test-mode=rndrw run

    #sysbench --test=fileio --num-threads=16 --file-total-size=3G --max-time=300 --file-test-mode=rndrw cleanup

      在测试结果中,有两个参数很值得我们关注,即每秒的请求数(Requests/sec)和总体的吞吐量(Total transferred),这两个参数对于评估磁盘的性能很有帮助。另外时间信息也非常有用,”approx. 95 percentile”尤其是大约95%的时间分布。这些数据对于评估磁盘性能十分有用。

      在完成测试后,需要将测试数据删除: sysbench --test=fileio cleanup

    对于Web服务器进行性能压力测试时可以考虑使用webbench工具进行。

    http://blog.csdn.net/sscsgss/article/details/47679691

    参考资料:   http://blog.csdn.net/clh604/article/details/12108477 

          http://blog.itpub.net/23490154/viewspace-1062521/

            http://mrxiong.blog.51cto.com/287318/1569651

  • 相关阅读:
    数据库查询服务框架
    postgresql清理工具
    postgre索引
    SAP模块一句话入门(专业术语的理解)
    SAP订单结算详解
    SAP Datasheet
    ASP.NET MVC5 网站开发实践
    VMware S/4 HANA OP 1511虚拟机下载,64G内存限制解决方案
    SAP标准教材列表
    SAP文章链接
  • 原文地址:https://www.cnblogs.com/wjoyxt/p/4822929.html
Copyright © 2020-2023  润新知