zoukankan      html  css  js  c++  java
  • sysybench-测试工具

    最近工作中用到了sysbench,查阅了很多资料,最终把自己的一些笔记分享出来。

    其中有许多都是出自博客、论坛。在此,道一声谢谢。如果侵犯了你的权益,告诉我,我删掉。

    一、安装

    sysbench源码安装

    1、预安装与环境准备

    1.0 安装mysql数据库

    1.1 登录服务器,安装必要的依赖
    yum -y install make automake libtool pkgconfig libaio-devel vim-common

    1.2 下载并解压缩sysbench源码包
    wget https://codeload.github.com/akopytov/sysbench/zip/master
    unzip master

    1.3 开始安装
    cd sysbench-master/
    ./autogen.sh ##生成configure文件
    ./configure --prefix=/usr/local/sysbench/ ##安装到哪个目录
    --with-mysql #如果想要让 sysbench 支持 pgsql/oracle 的话,就需要在编译的时候加上参数--with-pgsql或者--with-oracle
    --with-mysql-includes=/usr/local/mysql/include ##1.0已经安装了mysql,此处指定mysql数据库的相应目录
    --with-mysql-libs=/usr/local/mysql/lib ##1.0已经安装了mysql,此处指定mysql数据库的相应目录

    1.4 如果想要支持pgsql/oracle,需要提前安装pgsql/oracle数据库,或者将lib库拷贝过来,编译时指定。

    2、安装sysbench
    安装
    make
    make install

    3、检查
    去安装目录下(/usr/local/sysbench/) 找到 sysbench
    ./sysbench --version
    输出版本号即可

     二、使用

    Oracle 数据库 sysbench 压力测试

    1、环境准备:
    1.1 OS: centos 7.x
    1.2 DB:Oracle 11.2.0.4

    2、工具和数据库可以不在一台主机上,不过,工具所在的服务器也要有oracle软件。
    可以直接把数据库软件(oracle安装后目录结构一般为 /XXX/app/oracle/XXX,则可以是app目录)打包拷贝过来就可以。

    3、sysdba角色登录oracle数据库创建sysbench用户并赋予权限
    create user sysbench identified by sysbench;
    grant connect,resource to sysbench;

    4、工具所在服务器上执行
    4.0 此次采用别人编译安装打包好的sysbench:  -----刚开始采用1.1和1.0,想要自己安装,浪费了许多时间。最后才发现,0.5以后,好像就不支持oracle了,只得已选择别人打包好的,先用着。

    cd /root/sysbench/ ##切换到一个合适的目录下,空间需求,10M即可
    git clone https://github.com/osdba/sysbench_lua
    git clone https://github.com/osdba/sysbench_bin.git

    4.1 export ORACLE_HOME=/mnt/app/oracle/product/11.2.0/db_1/
    export LD_LIBRARY_PATH=/mnt/app/oracle/product/11.2.0/db_1/lib

    4.2 解压缩
    unzip sysbench_lua-master.zip
    unzip sysbench_bin-master.zip

    4.3 开始测试
    cd /root/sysbench/sysbench_bin-master/bin
    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000 --num-threads=2 --report-interval=1 prepare

    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000000 --num-threads=2 --report-interval=1 run

    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000 --num-threads=2 --report-interval=1 cleanup

    4.4 简要参数介绍
    --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua ##表示调用 .../oltp.lua 脚本进行 oltp 模式测试
    --db-driver=oracle #指定数据库引擎
    --oracle-db=orcl #指定数据库实例
    --oracle-user=sysbench #数据库账号
    --oracle-password=Aa123456 #上一条中指定用户的密码
    --oltp-table-name=sysbench #测试时使用到的表名,默认是sbtest
    --oltp-table-size=1000 #每个测试表填充数据量,默认是10000
    --rand-init=on #每个测试表都是用随机数据来填充
    --oltp-tables-count=2 #指定表的数量
    --max-time=60 #总执行时间,单位为s,默认值为0。持续压测时长不小于30分钟,否则测试数据可能不具参考意义。
    #该值非硬性指标,比如某一事物开始了,那么会等待事务结束。所以设置了60秒,可能是61秒、62秒。
    --max-requests=1000 #总请求数,默认值为10000,表示总请求数为 10000。0 标识不设置。
    #总执行时长(max-time) 和 总请求数(max-requests),设置一个即可。
    --num-threads=2 #使用的线程数量,默认值为1,表示发起N个并发连接
    --report-interval=1 #表示N秒输出一次测试进度报告,0表示关闭测试进度报告输出,仅输出最终的报告结果,默认值为0
    --rand-type=uniform #表示随机类型为固定模式,其他几个可选随机模式:
    #uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
    prepare/run/cleanup #测试前准备,包括创建表结构,构造数据/开始测试/测试完成后清理数据和表结构

    4.5 其他参数参考(这部分主要来自CSDN的大神,我只是搬运工~~)

    sysbench的测试主要包括以下几个方面:

    (1)磁盘io性能

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

    (2)cpu性能

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

    (3)内存分配及传输速度
    #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

    (4)线程性能

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

    (5)mutex性能

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

    (6)OLTP基准测试

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

    5、输出结果解读

    5.1、CPU测试
    ./sysbench_ora --test=cpu --db-driver=oracle --oracle-db=orcl
    --oracle-user=sysbench --oracle-password=Aa123456 --max-time=60 --max-requests=1000 run

    General statistics:
    total time: 43.2617s #总运行时间
    total number of events: 10000 #循环的次数
    total time taken by event execution: 43.2237s #循环的执行时间
    response time:
    min: 3.83ms #最小单次执行时间
    avg: 4.32ms #平均单次执行时间
    max: 67.89ms #最长单次执行时间
    approx. 95 percentile: 5.33ms #除去最高的5%剩余的95%中最长的执行时间

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

    #######################################################################################################

    5.2、OLTP测试
    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000 --num-threads=2 --report-interval=1 prepare

    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000000 --num-threads=2 --report-interval=1 run

    ./sysbench_ora --test=/root/sysbench/sysbench_lua-master/lua/oltp.lua --db-driver=oracle
    --oltp-table-name=sysbench --oltp-table-size=1000 --oltp-tables-count=2
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --max-requests=1000 --num-threads=2 --report-interval=1 cleanup

    OLTP test statistics:
    queries performed:
    read: 8823206 #读总数
    write: 2520916 #写总数
    other: 1260458 #其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
    total: 12604580 #全部总数
    transactions: 630229 (174.94 per sec.) #总事务数(每秒事务数)
    deadlocks: 0 (0.00 per sec.) #发生死锁总数
    read/write requests: 11344122 (3148.86 per sec.) #读写总数(每秒读写次数)
    other operations: 1260458 (349.87 per sec.) #其他操作总数(每秒其他操作次数)
    General statistics: #一些统计结果
    total time: 3602.6152s #总耗时
    total number of events: 630229 #共发生多少事务数
    total time taken by event execution: 921887.7227s #所有事务耗时相加(不考虑并行因素)
    response time: #响应时间
    min: 6.52ms #最小耗时
    avg: 1462.78ms #平均耗时
    max: 9918.51ms #最长耗时
    approx. 99 percentile: 3265.01ms #超过99%平均耗时
    Threads fairness: #线程的稳定性
    events (avg/stddev): 2461.8320/34.60 #事件(平均值/偏差)
    execution time (avg/stddev): 3601.1239/0.63 #执行时间(平均值/偏差)

    #######################################################################################################

    5.3、threads的测试

    ./sysbench_ora --test=threads --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --num-threads=20 --thread-yields=500 --thread-locks=2222 run

    Threads started!


    General statistics:
    total time: 0.4057s
    total number of events: 10000
    total time taken by event execution: 8.0491s
    response time:
    min: 0.48ms
    avg: 0.80ms
    max: 6.27ms
    approx. 95 percentile: 1.00ms

    Threads fairness:
    events (avg/stddev): 500.0000/61.06
    execution time (avg/stddev): 0.4025/0.00

    #######################################################################################################

    5.4、MUTEX测试

    ./sysbench_ora --test=mutex --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --num-threads=20 --mutex-num=10240 --mutex-locks=1000000 --mutex-loops=50000000 run

    Threads started!


    General statistics:
    total time: 8.7911s
    total number of events: 20
    total time taken by event execution: 174.5552s
    response time:
    min: 8590.99ms
    avg: 8727.76ms
    max: 8791.03ms
    approx. 95 percentile: 8788.80ms

    Threads fairness:
    events (avg/stddev): 1.0000/0.00
    execution time (avg/stddev): 8.7278/0.06

    #######################################################################################################

    5.5、MEMORY测试

    ./sysbench_ora --test=memory --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    --max-time=60 --memory-block-size=8k --memory-total-size=100G --memory-access-mode=seq run

    Threads started!

    Operations performed: 13107200 (408382.85 ops/sec)

    102400.00 MB transferred (3190.49 MB/sec)


    General statistics:
    total time: 32.0954s --总体花费时间
    total number of events: 13107200 --访问内存的次数 100*1024(M)=8K*1024*128
    total time taken by event execution: 16.8145s --纯测试发生的总时间
    response time:
    min: 0.00ms
    avg: 0.00ms
    max: 0.38ms
    approx. 95 percentile: 0.00ms

    Threads fairness:
    events (avg/stddev): 13107200.0000/0.00
    execution time (avg/stddev): 16.8145/0.00


    #######################################################################################################

    5.6、FILEIO测试

    ./sysbench_ora --test=fileio --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    file-num=256 --file-block-size=8K --file-total-size=2G --file-test-mode=rndrw prepare

    ./sysbench_ora --test=fileio --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    file-num=256 --file-block-size=8K --file-total-size=2G --file-test-mode=rndrw run

    ./sysbench_ora --test=fileio --db-driver=oracle
    --oracle-db=orcl --oracle-user=sysbench --oracle-password=Aa123456
    file-num=256 --file-block-size=8K --file-total-size=2G --file-test-mode=cleanup

    General statistics:
    total time: 57.1536s --总运行时间
    total number of events: 10000 --测试次数
    total time taken by event execution: 49.6440s --其中纯花费在测试上的时间
    response time:
    min: 0.00ms --最小时间
    avg: 4.96ms --平均时间
    max: 88.10ms --最大时间
    approx. 95 percentile: 21.75ms --去除最高的5%后的最大时间


    Threads fairness:
    events (avg/stddev): 10000.0000/0.00

    #######################################################################################################

  • 相关阅读:
    用例建模Use Case Modeling——传感器智能分析引擎
    结合工程实践分析同类软件产品-抖音快手微视
    为知笔记快捷键
    unity__细碎小知识
    unity__脚本实例化
    unity_GUI
    unity__音频
    关于js获取赋值,遍历属性
    关于节点,jquery的使用以及动画效果
    关于数组,对象,构造器的写法以及事件的使用
  • 原文地址:https://www.cnblogs.com/smallfishy/p/13616963.html
Copyright © 2011-2022 走看看