sysbench -- CentOS性能测试工具 – sysbench

前端之家收集整理的这篇文章主要介绍了sysbench -- CentOS性能测试工具 – sysbench前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

sysbench是一款开源的多线程性能测试工具,可以执行cpu/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MysqL/Oracle /Postgresql。本文只是简单演示一下几种测试的用法,后续准备利用sysbench来对MysqL进行一系列的测试。具体的一些参数设置,需要 根据不同的测试要求来进行调整.

编译安装

# wget -c http://sourceforge.net/projects/sysbench/files/sysbench/0.4.12/sysbench-0.4.12.tar.gz/download

#tar zxvf sysbench-0.4.12.tar.gz

#cd sysbench-0.4.12

#./configure && make && make install Linux学习,http:// linux.it.net.cn

如果需要测试Oracle/Postgresql,则在configure时需要加上–with-oracle或者–with-pgsql参数

参数

[root@localhost sysbench]# ./sysbench

测试用例:
sysbench [general-options]… –test=<test-name> [test-options]… command Linux学习,http:// linux.it.net.cn

通用选项:
–num-threads=N 创建测试线程的数目。默认为1.
–max-requests=N 请求的最大数目。默认为10000,0代表不限制。
–max-time=N 最大执行时间,单位是s。默认是0,不限制。
–forced-shutdown=STRING 超过max-time强制中断。默认是off。]
–thread-stack-size=SIZE 每个线程的堆栈大小。默认是32K。
–init-rng=[on|off] 在测试开始时是否初始化随机数发生器。默认是off。
–test=STRING 指定测试项目名称
–debug=[on|off] 是否显示更多的调试信息。默认是off。
–validate=[on|off] 在可能情况下执行验证检查。默认是off。

测试项目:
fileio – File I/O test
cpucpu performance test
memory – Memory functions speed test
threads – Threads subsystem performance test
mutex – Mutex performance test(互斥性能测试)
oltp – OLTP test

指令: prepare(测试前准备工作) run(正式测试) cleanup(测试后删掉测试数据) help version

See ‘sysbench –test=<name> help’ for a list of options for each test. 查看每个测试项目的更多选项列表。

[root@localhost bin]# ./sysbench –test=fileio help
–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 Linux学习,http:// linux.it.net.cn
–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

[root@localhost bin]# ./sysbench –test=cpu help
cpu-max-prime=N 最大质数发生器数量。默认是10000

[root@localhost bin]# ./sysbench –test=memory help
–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

[root@localhost bin]# ./sysbench –test=threads help
–thread-yields=N 每个请求产生多少个线程。默认是1000
–thread-locks=N 每个线程的锁的数量。默认是8

[root@localhost bin]# ./sysbench –test=mutex help
–mutex-num=N 数组互斥的总大小。默认是4096
–mutex-locks=N 每个线程互斥锁的数量。默认是50000
–mutex-loops=N 内部互斥锁的空循环数量。默认是10000

[root@localhost bin]# ./sysbench –test=oltp help
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 Linux学习,http:// linux.it.net.cn
–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 IT网,http://www.it.net.cn
–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] Linux学习,http:// linux.it.net.cn

Compiled-in database drivers:
MysqLMysqL 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 [] Linux学习,http:// linux.it.net.cn

测试

1、cpu测试 IT网,http://www.it.net.cn

[root@localhost bin]# ./sysbench –test=cpucpu-max-prime=20000 run

sysbench 0.4.12: multi-threaded system evaluation benchmark Linux学习,http:// linux.it.net.cn

Number of threads: 1 IT网,http://www.it.net.cn

Doing cpu performance benchmark

Threads started!
Done.

Maximum prime number checked in cpu test: 20000
Test execution summary:
total time: 31.9364s
total number of events: 10000
total time taken by event execution: 31.9334
per-request statistics:
min: 3.18ms
avg: 3.19ms
max: 3.60ms IT网,http://www.it.net.cn
approx. 95 percentile: 3.20ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 31.9334/0.00 IT网,http://www.it.net.cn

2、线程数测试

thread-locks小于线程数除以2,lock越少,处理时间越长。

# ./sysbench –test=threads –num-threads=512 –thread-yields=100 –thread-locks=2 run

sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:Number of threads: 512
Doing thread subsystem performance test

Thread yields per test: 100 Locks used: 2

Threads started!

WARNING: Operation time (0.000000) is less than minimal counted value,counting as 1.000000

WARNING: Percentile statistics will be inaccurateDone. Linux学习,http:// linux.it.net.cn

Test execution summary:

total time: 4.1759s

total number of events: 10000

total time taken by event execution: 2038.5959

per-request statistics:

min: 0.00ms

avg: 203.86ms

max: 2735.47ms

approx. 95 percentile: 829.60ms
Threads fairness:

events (avg/stddev): 19.5312/8.26

execution time (avg/stddev): 3.9816/0.04

3、磁盘IO性能测试 Linux学习,http:// linux.it.net.cn

首先生成需要的测试文件文件总大小3G,16个并发线程,随机读写模式。执行完后会在当前目录下生成一堆小文件

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw prepare

sysbench 0.4.12: multi-threaded system evaluation benchmark

128 files,24576Kb each,3072Mb total Linux学习,http:// linux.it.net.cn

Creating files for the test…

开始测试: IT网,http://www.it.net.cn

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw run

sysbench 0.4.12: multi-threaded system evaluation benchmark

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

Extra file open flags: 0 Linux学习,http:// linux.it.net.cn

128 files,24Mb each

3Gb total file size

Block size 16Kb

Number of random requests for random IO: 10000

Read/Write ratio for combined random IO test: 1.50 IT网,http://www.it.net.cn

Periodic FSYNC enabled,calling fsync() each 100 requests

.Calling fsync() at the end of test,Enabled.

Using synchronous I/O modeDoing random r/w test

Threads started! Linux学习,http:// linux.it.net.cn

WARNING: Operation time (0.000000) is less than minimal counted value,counting as 1.000000

WARNING: Percentile statistics will be inaccurateDone.

Operations performed: 6004 Read,3996 Write,12800 Other = 22800 TotalRead 93.812Mb Written 62.438Mb Total transferred 156.25Mb (6.472Mb/sec) 414.21 Requests/sec executed

Test execution summary: Linux学习,http:// linux.it.net.cn

total time: 24.1426s

total number of events: 10000

total time taken by event execution: 164.4243 IT网,http://www.it.net.cn

per-request statistics:

min: 0.00ms Linux学习,http:// linux.it.net.cn

avg: 16.44ms

max: 821.08ms approx. 95 percentile: 102.40ms
Threads fairness:

events (avg/stddev): 625.0000/63.99 e

xecution time (avg/stddev): 10.2765/0.62

清理现场

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw cleanup

sysbench 0.4.12: multi-threaded system evaluation benchmark

Removing test files…

4、内存测试

下面的参数指定了本次测试整个过程是在内存中传输 1G 的数据量,每个 block 大小为 8K。

./sysbench –test=memory –num-threads=64 –memory-block-size=8192 –memory-total-size=1G run

sysbench 0.4.12: multi-threaded system evaluation benchmark Linux学习,http:// linux.it.net.cn

Running the test with following options:

Number of threads: 64

Doing memory operations speed test

Memory block size: 8K

Memory transfer size: 1024M

Memory operations type: writeMemory scope type: globalThreads started!(last message repeated 1 times)

WARNING: Operation time (0.000000) is less than minimal counted value,counting as 1.000000

WARNING: Percentile statistics will be inaccurate(last message repeated 1 times)Done.

Operations performed: 131072 (416391.08 ops/sec)

1024.00 MB transferred (3253.06 MB/sec) Linux学习,http:// linux.it.net.cn

Test execution summary:

total time: 0.3148s

total number of events: 131072

total time taken by event execution: 17.5553

per-request statistics:

min: 0.00ms

avg: 0.13ms

max: 289.55ms

approx. 95 percentile: 0.00ms
Threads fairness:

events (avg/stddev): 2048.0000/4854.85 Linux学习,http:// linux.it.net.cn

execution time (avg/stddev): 0.2743/0.04

5、Mutex测试 Linux学习,http:// linux.it.net.cn

测试mutex
[root@localhost ]# ./sysbench –test=mutex –num-threads=1500 –max-requests=2000 –mutex-num=10240 –mutex-locks=100000

–mutex-loops=15000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark Linux学习,http:// linux.it.net.cn

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

Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 74.0710s
total number of events: 1500
total time taken by event execution: 5410.6925
per-request statistics:
min: 485.77ms
avg: 3607.13ms
max: 13770.44ms


approx. 95 percentile: 12489.67ms

Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 3.6071/3.97

6、MysqL数据库测试


首先需要创建默认的sbtest数据库,或者使用–MysqL-db指定一个已经存在的数据库

生成测试数据,引擎为myisam,表大小为1000000条记录

[root@localhost ]# ./sysbench --test=oltp --MysqL-table-engine=myisam --oltp-table-size=1000000 \
--MysqL-user=root --MysqL-socket=/opt/MysqL/run/MysqL.sock 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'...

root@sbtest 11:42:18>desc sbtest.sbtest;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| k     | int(10) unsigned | NO   | MUL | 0       |                |
| c     | char(120)        | NO   |     |         |                |
| pad   | char(60)         | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+

执行测试

[root@localhost ]# ./sysbench --test=oltp --MysqL-table-engine=myisam --oltp-table-size=1000000 \
--MysqL-user=root --MysqL-socket=/opt/MysqL/run/MysqL.sock run Linux学习,http:// linux.it.net.cn
sysbench 0.4.12:  multi-threaded system evaluation benchmark

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

Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,1 pct of values are returned in 75 pct cases)
Using "LOCK TABLES WRITE" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Threads started!
Done.

OLTP test statistics:
    queries performed:
        read:                            140000
        write:                           50000
        other:                           20000
        total:                           210000
    transactions:                        10000  (336.64 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 190000 (6396.11 per sec.)
    other operations:                    20000  (673.27 per sec.)

Test execution summary:
    total time:                          29.7056s
    total number of events:              10000
    total time taken by event execution: 29.6301
    per-request statistics:
         min:                                  2.27ms
         avg:                                  2.96ms
         max:                                 43.88ms
         approx.  95 percentile:               3.36ms

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

清理现场

[root@localhost ]# ./sysbench--test=oltp --MysqL-table-engine=myisam --oltp-table-size=1000000 \
--MysqL-user=root --MysqL-socket=/opt/MysqL/run/MysqL.sock cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

No DB drivers specified,using MysqL
Dropping table 'sbtest'...
Done.

猜你在找的CentOS相关文章