zoukankan      html  css  js  c++  java
  • 关于sysbench的使用

    一、工具说明

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

    sysbench的测试可运用:

    
    CPU性能
    磁盘IO性能
    调动程序性能
    内存分配及传输速度
    POSIX线程性能
    数据库性能
    

    安装说明

    https://link.zhihu.com/?target=https%3A//www.cnblogs.com/pdlife/p/6698957.html

    使用说明

    测试fileio命令帮助

    sysbench --test=fileio help
    参数详解:
    
    --file-num=N          代表生成测试文件的数量,默认为128。
    --file-block-size=N      测试时所使用文件块的大小,如果想磁盘针对innodb存储引擎进行测试,可以将其设置为16384,即innodb存储引擎页的大小。默认为16384。
    --file-total-size=SIZE     创建测试文件的总大小,默认为2G大小。
    --file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)。
    --file-io-mode=STRING   文件操作的模式,sync(同步),async(异步),fastmmap(快速mmap),slowmmap(慢速mmap),默认为sync同步模式。
    --file-async-backlog=N   对应每个线程队列的异步操作数,默认为128。
    --file-extra-flags=STRING 打开文件时的选项,这是与API相关的参数。
    --file-fsync-freq=N      执行fsync()函数的频率。fsync主要是同步磁盘文件,因为可能有系统和磁盘缓冲的关系。 0代表不使用fsync函数。默认值为100。
    --file-fsync-all=[on|off]  每执行完一次写操作,就执行一次fsync。默认为off。
    --file-fsync-end=[on|off] 在测试结束时执行fsync函数。默认为on。
    --file-fsync-mode=STRING文件同步函数的选择,同样是和API相关的参数,由于多个操作系统对于fdatasync支持不同,因此不建议使用fdatasync。默认为fsync。
    --file-merged-requests=N 大多情况下,合并可能的IO的请求数,默认为0。
    --file-rw-ratio=N         测试时的读写比例,默认时为1.5,即可3:2
    

    测试CPU命令帮助

    sysbench --test=cpu help

    参数详解:
      --cpu-max-prime=N      用来选项指定最大的素数,具体参数可以根据CPU的性能来设置,默认为10000
    

    测试memory命令帮助

    sysbench --test=memory help

    参数详解:
      --memory-block-size=SIZE      测试内存块的大小,默认为1K
      --memory-total-size=SIZE       数据传输的总大小,默认为100G
      --memory-scope=STRING       内存访问的范围,包括全局和本地范围,默认为global
      --memory-hugetlb=[on|off]     是否从HugeTLB池分配内存的开关,默认为off
      --memory-oper=STRING        内存操作的类型,包括read, write, none,默认为write
      --memory-access-mode=STRING 内存访问模式,包括seq,rnd两种模式,默认为seq
    

    测试threads命令帮助

    sysbench --test-threads help

    参数详解: 
      --thread-yields=N      指定每个请求的压力,默认为1000
      --thread-locks=N       指定每个线程的锁数量,默认为8
    

    测试mutex命令帮助

    sysbench --test=mutex help

    参数详解:
      --mutex-num=N    数组互斥的总大小。默认是4096
      --mutex-locks=N    每个线程互斥锁的数量。默认是50000
      --mutex-loops=N    内部互斥锁的空循环数量。默认是10000
    

    测试otlp命令帮助

    sysbench --test=otlp help

    参数详解:
      --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-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
    

    对mysql事务型OLTP的测试:

    对于mysql的OLTP测试,和file一样,同样需要经历prepare,run,cleanup三个阶段。

    1. prepare准备阶段

    prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为
    
    sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:
    
    [root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --db-driver=mysql --mysql-socket=/data/mysqlsoft3307/mysql.sock --mysql-user=dba_manager  --mysql-password='111111' --mysql-db=test prepare
    
    sysbench 0.4.12:  multi-threaded system evaluation benchmark
    
    Creating table 'sbtest'...
    
    Creating 10 records in table 'sbtest'...
    

    run运行测试

    接下来对上面产生的表进行oltp的测试:

    接下来对上面产生的表进行oltp的测试:
    
    [root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --oltp-read-only=off --init-rng=on --num-threads=16 
    --max-requests=0 --oltp-dist-type=uniform --max-time=3600 --mysql-user=dba_manager  --mysql-password='111111' --db-driver=mysql 
    --mysql-socket=/data/mysqlsoft3307/mysql.sock run > result.log
    
    参数说明:
    
     --max-time=3600 指定测试时长为1小时
    
     --mysql-db=test 指定测试的数据库名
    
     
    
    [root@db-master sysbench]# cat  result.log 
    
    sysbench 0.4.12:  multi-threaded system evaluation benchmark
    
    Running the test with following options:
    
    Number of threads: 16
    
    Initializing random number generator from timer.
    
    Doing OLTP test.
    
    Running mixed OLTP test
    
    Using Uniform distribution
    
    Using "BEGIN" for starting transactions
    
    Using auto_inc on the id column
    
    Threads started!
    
    Time limit exceeded, exiting...
    
    (last message repeated 15 times)
    
    Done.
    
    OLTP test statistics:
    
        queries performed:
    
            read:                            137346874
    
            write:                           49052449
    
            other:                           19620980
    
            total:                           206020303
    
        transactions:                        9810489 (2725.13 per sec.)
    
        deadlocks:                           2      (0.00 per sec.)
    
        read/write requests:                 186399323 (51777.50 per sec.)
    
        other operations:                    19620980 (5450.26 per sec.)
    
    Test execution summary:
    
        total time:                          3600.0060s
    
        total number of events:              9810489
    
        total time taken by event execution: 57542.1464
    
        per-request statistics:
    
             min:                                  3.00ms
    
             avg:                                  5.87ms
    
             max:                                212.09ms
    
             approx.  95 percentile:               8.44ms
    
    Threads fairness:
    
        events (avg/stddev):           613155.5625/1486.47
    
        execution time (avg/stddev):   3596.3842/0.01
    
    以上测试结果显示了很多操作的详细信息,transactions代表测试结果的评判标准即TPS,上述测试结果是 2725.13 per sec.
    
    可以对数据库进行调优后,再使用sysbench对OLTP进行测试,看看TPS是不是会有所提高。
    
    注意:sysbench的测试只是基准测试,并不能代表实际企业环境下的性能指标
    
  • 相关阅读:
    http缓存
    深入理解vertical-align
    WebSocket
    mongodb 语法小结
    鸡肋工具-Oracle建表工具
    Ajax 实现导出文件-支持批量
    Springboot 热部署
    RabbitMq(7)消息延时推送
    linux常用符号命令
    linux常用命令之文档
  • 原文地址:https://www.cnblogs.com/lzmbdr/p/13431371.html
Copyright © 2011-2022 走看看