基准测试工具sysbench简介

35 篇文章 0 订阅
基准测试工具sysbench简介

sysbench是一个跨平台的基准测试工具,可以测试CPU、文件I/O、线程、内存、数据库性能等。

简要说明
$ man sysbench 
SYSBENCH(1)                                   sysbench User Manual                                  SYSBENCH(1)

NAME
       sysbench - A modular, cross-platform and multi-threaded benchmark tool.

SYNOPSIS
       sysbench [common-options] --test=name [test-options] command

       sysbench [{-h | --help} | {-v | --version}]

DESCRIPTION
       SysBench is a modular, cross-platform and multi-threaded benchmark tool for evaluating OS parameters
       that are important for a system running a database under intensive load.

       The idea of this benchmark suite is to quickly get an impression about system performance without
       setting up complex database benchmarks or even without installing a database at all.

       Current features allow to test the following system parameters:

       o   file I/O performance

       o   scheduler performance

       o   memory allocation and transfer speed

       o   POSIX threads implementation performance

       o   database server performance

       The design is very simple. SysBench runs a specified number of threads and they all execute requests in
       parallel. The actual workload produced by requests depends on the specified test mode. You can limit
       either the total number of requests or the total time for the benchmark, or both.

       Available test modes are implemented by compiled-in modules, and SysBench was designed to make adding
       new test modes an easy task. Each test mode may have additional (or workload-specific) options.

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 [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --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



测试之前,需要先安装sysbench(ubuntu):
root@ubuntu:~# apt-get install sysbench

1. CPU 测试

第一台机器的CPU配置
root@ubuntu:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU T3400 @ 2.16GHz
stepping : 13
microcode : 0xa3
cpu MHz : 2161.250
cache size : 1024 KB

下面的测试会计算20000以内的所有素数,计总用时55.1282s:
root@ubuntu:~# sysbench --test=cpu --cpu-max-prime=20000 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: 20000


Test execution summary:
total time: 55.1283s
total number of events: 10000
total time taken by event execution: 55.1111
per-request statistics:
min: 5.03ms
avg: 5.51ms
max: 247.46ms
approx. 95 percentile: 5.80ms

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

换了一台机器:
root@db2a:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
stepping : 9
microcode : 0x13
cpu MHz : 2594.159
cache size : 3072 KB

做同样的测试,用时为上一台机器的一半:
root@db2a:~# sysbench --test=cpu --cpu-max-prime=20000 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: 20000


Test execution summary:
total time: 26.9383s
total number of events: 10000
total time taken by event execution: 26.9360
per-request statistics:
min: 2.55ms
avg: 2.69ms
max: 6.01ms
approx. 95 percentile: 2.92ms

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

当把threads数据增加到4时,用时进一步减少,只用了8.2513s:
root@db2a:~# sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run
sysbench 0.4.12: multi-threaded system evaluation benchmark

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

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 20000


Test execution summary:
total time: 8.2513s
total number of events: 10000
total time taken by event execution: 32.9676
per-request statistics:
min: 2.71ms
avg: 3.30ms
max: 31.77ms
approx. 95 percentile: 3.62ms

Threads fairness:
events (avg/stddev): 2500.0000/18.56
execution time (avg/stddev): 8.2419/0.01

===

2. 文件I/O测试

文件I/O测试分为三个阶段

2.1 准备阶段

准备阶段会生成所需文件,下面的命令生成了5G大小的文件,一共128个文件,每个40960Kb:
root@ubuntu:~/sysbenchtest# sysbench --test=fileio --file-total-size=5G prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark

128 files, 40960Kb each, 5120Mb total
Creating files for the test...

2.2 测试阶段

测试阶段对文件I/O做真正的测试,file-test-mode包括seqwr(sequential write), seqrewr(sequential rewrite), seqrd(sequential read),rndrd(random read),rndwr(random write),rndrw(combined random read/write), max-time指定了时间

root@ubuntu:~/sysbenchtest# sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Initializing random number generator from timer.


Extra file open flags: 0
128 files, 40Mb each
5Gb total file size
Block size 16Kb
Number of random requests for random IO: 0
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!
WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000
WARNING: Percentile statistics will be inaccurate
Time limit exceeded, exiting...
Done.

Operations performed: 362624 Read, 241749 Write, 773504 Other = 1377877 Total
Read 5.5332Gb Written 3.6888Gb Total transferred 9.222Gb (31.47Mb/sec)
2014.10 Requests/sec executed

Test execution summary:
total time: 300.0712s
total number of events: 604373
total time taken by event execution: 191.5464
per-request statistics:
min: 0.00ms
avg: 0.32ms
max: 586.87ms
approx. 95 percentile: 0.43ms

Threads fairness:
events (avg/stddev): 604373.0000/0.00
execution time (avg/stddev): 191.5464/0.00

2.3 清理阶段

使用clean up 选项,会删除所有的测试文件
root@ubuntu:~/sysbenchtest# sysbench --test=fileio --file-total-size=5G cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark

Removing test files...

3. MySQL的OLTP测试

之前的博客里有提到 mysqlslap可以对MySQL数据库性能做测试。sysbench也能做测试,下面的命令先在已经存在的数据库sample下创建了一张表sbtest,并插入了100万条数据:
root@ubuntu:~# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sample --mysql-user=root --mysql-password=qingsong prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...

下面的命令使用了8个线程,以只读模式测试了60s的时间:
root@ubuntu:~# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sample --mysql-user=root --mysql-password=qingsong --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
sysbench 0.4.12: multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.

OLTP test statistics:
queries performed:
read: 268688
write: 0
other: 38384
total: 307072
transactions: 19192 (319.77 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 268688 (4476.80 per sec.)
other operations: 38384 (639.54 per sec.)

Test execution summary:
total time: 60.0179s
total number of events: 19192
total time taken by event execution: 479.8520
per-request statistics:
min: 3.91ms
avg: 25.00ms
max: 551.52ms
approx. 95 percentile: 32.60ms

Threads fairness:
events (avg/stddev): 2399.0000/32.87
execution time (avg/stddev): 59.9815/0.00

可以看到,总的事务数为19192,每秒事务数为319.77个,以及一些其他的性能指标.

参考资料:《高性能MySQL》
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值