sysbench 安装、使用和测试

摘要:

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。当前功能允许测试的系统参数有:

file I/O performance (文件I / O性能)
scheduler performance (调度性能)
memory allocation and transfer speed (内存分配和传输速度)
POSIX threads implementation performance (POSIX线程执行绩效)
database server performance (OLTP benchmark) (数据库服务器性能)

选项说明(通用):

root@db2:~# sysbench
Missing required command argument.
Usage: #使用方法
sysbench [general-options]... --test=<test-name> [test-options]... command General options: #通用选项
--num-threads=N number of threads to use [1] #创建测试线程的数目。默认为1.
--max-requests=N limit for total number of requests [10000] #请求的最大数目。默认为10000,0代表不限制。
--max-time=N limit for total execution time in seconds [0] #最大执行时间,单位是s。默认是0,不限制。
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超过max-time强制中断。默认是off。
--thread-stack-size=SIZE size of stack per thread [32K] #每个线程的堆栈大小。默认是32K。
--init-rng=[on|off] initialize random number generator [off] #在测试开始时是否初始化随机数发生器。默认是off。
--test=STRING test to run #指定测试项目名称。
--debug=[on|off] print more debugging info [off] #是否显示更多的调试信息。默认是off。
--validate=[on|off] perform validation checks where possible [off] #在可能情况下执行验证检查。默认是off。
--help=[on|off] print help and exit #帮助信息。
--version=[on|off] print version and exit #版本信息。 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 #互斥性能测试
oltp - OLTP test # 数据库,事务处理 Commands: prepare:测试前准备工作; run:正式测试 cleanup:测试后删掉测试数据 help version See 'sysbench --test=<name> help' for a list of options for each test. #查看每个测试项目的更多选项列表

更多选项:

1):sysbench --test=fileio help

root@db2:~# sysbench  --test=fileio help
sysbench 0.4.12: multi-threaded system evaluation benchmark fileio options:
--file-num=N 创建测试文件的数量。默认是128
--file-block-size=N 测试时文件块的大小。默认是16384(16K)
--file-total-size=SIZE 测试文件的总大小。默认是2G
--file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
--file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
--file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
--file-fsync-freq=N 执行fsync()的频率。(0 – 不使用fsync())。默认是100
--file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off
--file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on
--file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
--file-merged-requests=N 如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0
--file-rw-ratio=N 测试时的读写比例。默认是1.5

2):sysbench --test=cpu help

--cpu-max-prime=N  最大质数发生器数量。默认是10000

3):sysbench --test=memory help

root@db2:~# sysbench  --test=memory help
sysbench 0.4.12: multi-threaded system evaluation benchmark memory options:
--memory-block-size=SIZE 测试时内存块大小。默认是1K
--memory-total-size=SIZE 传输数据的总大小。默认是100G
--memory-scope=STRING 内存访问范围{global,local}。默认是global
--memory-hugetlb=[on|off] 从HugeTLB池内存分配。默认是off
--memory-oper=STRING 内存操作类型。{read, write, none} 默认是write
--memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq

4):sysbench --test=threads help

sysbench 0.4.12:  multi-threaded system evaluation benchmark

threads options:
--thread-yields=N 每个请求产生多少个线程。默认是1000
--thread-locks=N 每个线程的锁的数量。默认是8

5):sysbench --test=mutex help

root@db2:~# sysbench  --test=mutex help
sysbench 0.4.12: multi-threaded system evaluation benchmark mutex options: --mutex-num=N 数组互斥的总大小。默认是4096
--mutex-locks=N 每个线程互斥锁的数量。默认是50000
--mutex-loops=N 内部互斥锁的空循环数量。默认是10000

6): sysbench --test=oltp help

root@db2:~# sysbench --test=oltp help
sysbench 0.4.12: multi-threaded system evaluation benchmark 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-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 General database options:
--db-driver=STRING 指定数据库驱动程序('help' to get list of available drivers)
--db-ps-mode=STRING编制报表使用模式{auto, disable} [auto]
Compiled-in database drivers:
mysql - MySQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port [3306]
--mysql-socket=STRING MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
--mysql-create-options=STRING additional options passed to CREATE TABLE []

测试:

1)测试CPU: sysbench --test=cpu --cpu-max-prime=2000 run

root@db2:~# sysbench --test=cpu --cpu-max-prime=2000 run
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!
Done. Maximum prime number checked in CPU test: 2000 Test execution summary:
total time: 3.7155s
total number of events: 10000
total time taken by event execution: 3.7041
per-request statistics:
min: 0.36ms
avg: 0.37ms
max: 2.53ms
approx. 95 percentile: 0.37ms Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 3.7041/0.00

2)测试线程:sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run

root@db2:~# sysbench  --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run
sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 500 Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 4
Threads started!
Done. Test execution summary:
total time: 1.0644s
total number of events: 10000
total time taken by event execution: 501.3952
per-request statistics:
min: 0.05ms
avg: 50.14ms
max: 587.05ms
approx. 95 percentile: 190.28ms Threads fairness:
events (avg/stddev): 20.0000/4.72
execution time (avg/stddev): 1.0028/0.01

3)测试IO:--num-threads 开启的线程 --file-total-size 总的文件大小

prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。

sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare

run阶段

sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run

清理测试时生成的文件

sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup

root@db2:~/io# sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark 128 files, 16384Kb each, 2048Mb total
Creating files for the test...
root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 20 Extra file open flags: 0
128 files, 16Mb each
2Gb total file size
Block size 16Kb
Number of random requests for random IO: 10000
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!
Done. Operations performed: 6010 Read, 3997 Write, 12803 Other = 22810 Total
Read 93.906Mb Written 62.453Mb Total transferred 156.36Mb (6.6668Mb/sec)
426.68 Requests/sec executed Test execution summary:
total time: 23.4534s
total number of events: 10007
total time taken by event execution: 111.5569
per-request statistics:
min: 0.01ms
avg: 11.15ms
max: 496.18ms
approx. 95 percentile: 53.05ms Threads fairness:
events (avg/stddev): 500.3500/37.50
execution time (avg/stddev): 5.5778/0.21 root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark Removing test files...

4)测试内存:sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run

sysbench 0.4.12:  multi-threaded system evaluation benchmark
Operations performed: 1310720 (396525.32 ops/sec)
10240.00 MB transferred (3097.85 MB/sec)
Test execution summary:
total time: 3.3055s
total number of events: 1310720
total time taken by event execution: 205.0560
per-request statistics:
min: 0.00ms
avg: 0.16ms
max: 1066.04ms
approx. 95 percentile: 0.02ms
Threads fairness:
events (avg/stddev): 13107.2000/3870.38
execution time (avg/stddev): 2.0506/0.28

5)测试mutex:sysbench –test=mutex –num-threads=100 –mutex-num=1000 –mutex-locks=100000 –mutex-loops=10000 run

Test execution summary:
total time: 12.5606s
total number of events: 100
total time taken by event execution: 1164.4236
per-request statistics:
min: 9551.87ms
avg: 11644.24ms
max: 12525.32ms
approx. 95 percentile: 12326.25ms
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 11.6442/0.59

6)测试oltp

# 下面的测试命令代表的是:对mysql进行oltp基准测试
# 表数量10
# 每表行数约50w(几乎delete多少就会insert的多少),并且是非事务的只读测试
# 持续60s
# 并发线程数12。 #1.prepare
sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \
--mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \
--report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \
--oltp-read-only=on --oltp-skip-trx=on \
--max-time=120 --num-threads=12 prepare #2.run
sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \
--mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \
--report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \
--oltp-read-only=on --oltp-skip-trx=on \
--max-time=120 --num-threads=12 run
} #3.clean
sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \
--mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \
--report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \
--oltp-read-only=on --oltp-skip-trx=on \
--max-time=120 --num-threads=12 clean
--test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--mysql-table-engine=innodb 表示选择测试表的存储引擎
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
#mysql-db=sbtest:测试使用的目标数据库,这个库名要事先创建
#--oltp-tables-count=10:产生表的数量
#--oltp-table-size=500000:每个表产生的记录行数
#--oltp-dist-type=uniform:指定随机取样类型,可选值有 uniform(均匀分布), Gaussian(高斯分布), special(空间分布)。默认是special
#--oltp-read-only=off:表示不止产生只读SQL,也就是使用oltp.lua时会采用读写混合模式。默认 off,如果设置为on,则不会产生update,delete,insert的sql。
#--oltp-test-mode=nontrx:执行模式,这里是非事务式的。可选值有simple,complex,nontrx。默认是complex
#simple:简单查询,SELECT c FROM sbtest WHERE id=N
#complex (advanced transactional):事务模式在开始和结束事务之前加上begin和commit, 一个事务里可以有多个语句,如点查询、范围查询、排序查询、更新、删除、插入等,并且为了不破坏测试表的数据,该模式下一条记录删除后会
在同一个事务里添加一条相同的记录。
#nontrx (non-transactional):与simple相似,但是可以进行update/insert等操作,所以如果做连续的对比压测,你可能需要重新cleanup,prepare。
#--oltp-skip-trx=[on|off]:省略begin/commit语句。默认是off
#
#--rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同
#
#--num-threads=12: 并发线程数,可以理解为模拟的客户端并发连接数
#--report-interval=10:表示每10s输出一次测试进度报告
#--max-requests=0:压力测试产生请求的总数,如果以下面的max-time来记,这个值设为0
#--max-time=120:压力测试的持续时间,这里是2分钟。

结果输出例子:

#每10秒钟报告一次测试结果,tps、每秒读、每秒写、95%以上的响应时长统计
[ 10s] threads: 8, tps: 66.60, reads: 943.67, writes: 269.62, response time: 431.72ms (95%), errors: 0.00, reconnects: 0.00
[ 20s] threads: 8, tps: 34.30, reads: 480.20, writes: 137.20, response time: 598.28ms (95%), errors: 0.00, reconnects: 0.00
[ 30s] threads: 8, tps: 36.60, reads: 512.40, writes: 146.40, response time: 494.87ms (95%), errors: 0.00, reconnects: 0.00 OLTP test statistics:
queries performed:
read: 941248 #读总数
write: 268928 #写总数
other: 134464 #其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: 1344640 #全部总数
transactions: 67232 (112.04 per sec.) #总事务数(每秒事务数)
read/write requests: 1210176 (2016.73 per sec.) #读写总数(每秒读写次数)
other operations: 134464 (224.08 per sec.) #其他操作总数(每秒其他操作次数)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.) General statistics:
total time: 600.0698s #总耗时
total number of events: 67232 #共发生多少事务数
total time taken by event execution: 4799.8569s # 所有事务耗时相加(不考虑并行因素)
response time:
min: 2.09ms #最小耗时
avg: 71.39ms #平均耗时
max: 839.32ms #最大耗时
approx. 95 percentile: 309.40ms 超过95%平均耗时 Threads fairness:
events (avg/stddev): 8404.0000/17.56
execution time (avg/stddev): 599.9821/0.02

sysbench使用指南的更多相关文章

  1. sysbench 数据库性能测试工具的使用

    sysbench 数据库性能测试 Mac上安装sysbench测试工具 brew install sysbench 测试sysbench 是否安装成功 //执行这条指令 sysbench cpu -- ...

  2. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  3. UE4新手之编程指南

    虚幻引擎4为程序员提供了两套工具集,可共同使用来加速开发的工作流程. 新的游戏类.Slate和Canvas用户接口元素以及编辑器功能可以使用C++语言来编写,并且在使用Visual Studio 或 ...

  4. JavaScript权威指南 - 对象

    JavaScript对象可以看作是属性的无序集合,每个属性就是一个键值对,可增可删. JavaScript中的所有事物都是对象:字符串.数字.数组.日期,等等. JavaScript对象除了可以保持自 ...

  5. JavaScript权威指南 - 数组

    JavaScript数组是一种特殊类型的对象. JavaScript数组元素可以为任意类型,最大容纳232-1个元素. JavaScript数组是动态的,有新元素添加时,自动更新length属性. J ...

  6. const extern static 终极指南

    const extern static 终极指南 不管是从事哪种语言的开发工作,const extern static 这三个关键字的用法和原理都是我们必须明白的.本文将对此做出非常详细的讲解. co ...

  7. Atitit.研发管理软件公司的软资产列表指南

    Atitit.研发管理软件公司的软资产列表指南 1. Isv模型下的软资产1 2. 实现层面implet1 3. 规范spec层1 4. 法则定律等val层的总结2 1. Isv模型下的软资产 Sof ...

  8. HA 高可用软件系统保养指南

    又过了一年 618,六月是公司一年一度的大促月,一般提前一个月各系统就会减少需求和功能的开发,转而更多去关注系统可用性.稳定性和管控性等方面的非功能需求.大促前的准备工作一般叫作「备战」,可以把线上运 ...

  9. 第六代智能英特尔® 酷睿™ 处理器图形 API 开发人员指南

    欢迎查看第六代智能英特尔® 酷睿™ 处理器图形 API 开发人员指南,该处理器可为开发人员和最终用户提供领先的 CPU 和图形性能增强.各种新特性和功能以及显著提高的性能. 本指南旨在帮助软件开发人员 ...

随机推荐

  1. php 把一个数组分成有n个元素的二维数组的算法

    一.第一种解法 <?php //把一个数组分成几个数组 //$arr 是数组 //$num 是数组的个数 function partition($arr,$num){ //数组的个数 $list ...

  2. 【C++】双向线性链表容器的实现

    // 双向线性链表容器 #include <cstring> #include <iostream> #include <stdexcept> using name ...

  3. 批量配置SSH 免密钥登录脚本

    [root@c3-zabbix-serv hurl]# cat sendsshkey.sh    #!/bin/bash  if [ -z $1 ]; then echo "Usage  : ...

  4. Delphi中ARC内存管理的方向

    随着即将发布的10.3版本,RAD Studio R&D和PM团队正在制作Delphi在内存管理方面的新方向. 几年前,当Embarcadero开始为Windows以外的平台构建新的Delph ...

  5. 第三章、Tiny4412 U-BOOT移植三 时钟设置【转】

    本文转自:http://blog.csdn.net/eshing/article/details/37521789 这一章说明配置时钟频率基本原理 OK,接着说,这次先讲讲CPU的系统时钟.U-BOO ...

  6. IDEA Spark Streaming Kafka数据源-Producer

    import java.util import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRe ...

  7. IDEA Spark Streaming 操作(套接字流)

    import org.apache.spark.SparkConf import org.apache.spark.streaming.{Seconds, StreamingContext} obje ...

  8. IBatis异常: Cannot find class: VARCHAR

    今天再项目里添加新功能时,突然爆出 org.springframework.beans.factory.BeanCreationException: Error creating bean with ...

  9. Magnetic Storms

    http://acm.timus.ru/problem.aspx?space=1&num=1126 简单的线段树求区间最值 #include <stdio.h> #include ...

  10. VB.NET学习体会

    注:本文写于2018年01月28日,首先发表于CSDN博客"aopstudio的博客"上 下学期要学习VB.NET程序设计课程,这几天在家开始自习.在自习的过程中发现VB.NET和 ...