十二月 28th, 2009

测试工具sysbench 测试数据

sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。关于这个项目的详细介绍看:http://sysbench.sourceforge.net。
它主要包括以下几种方式的测试:
1、cpu性能
2、磁盘io性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、Mysql数据库性能(OLTP基准测试)

sysbench支持 MySQL,pgsql,oracle 这3种数据库。

一、安装
首先,在 http://sourceforge.net/projects/sysbench 下载源码包。

接下来,按照以下步骤安装:

[root@xutest /]#tar zxf sysbench-0.4.12.tar.gz
[root@xutest /]#cd sysbench-0.4.12
[root@xutest /]#./autogen.sh
[root@xutest /]#./configure && make && make install
[root@xutest /]# strip /usr/local/bin/sysbench

或者
yum install sysbench # 版本是 0.4.10

如果 MySQL 安装在标准默认目录下的可以直接按照以上步骤安装,如果 MySQL不是安装在默认路径下,那么就需要自己指定 MySQL 的路径。比如我的 MySQL 喜欢自己安装在 /opt/mysql 下,则按照以下方法编译:
[root@xutest /]#./configure –with-mysql-includes=/opt/mysql/include –with-mysql-libs=/opt/mysql/lib && make && make install

当然了,用上面的参数编译的话,就要确保你的 MySQL lib目录下有对应的 so 文件,如果没有,可以自己下载 devel 或者 share 包来安装。
另外,如果想要让 sysbench 支持 pgsql/oracle 的话,就需要在编译的时候加上参数:
–with-pgsql
或者
–with-oracle
这2个参数默认是关闭的,只有 MySQL 是默认支持的。

二、测试
编译成功之后,就要开始测试各种性能了,测试的方法官网网站上说明了非常的详细,根据官网的说明文档测试的步骤大致如下:

1、cpu性能测试

[root@xutest /]#sysbench –test=cpu –cpu-max-prime=20000 run

cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值。

2、线程测试

[root@xutest /]#sysbench –test=threads –num-threads=64 –thread-yields=100 –thread-locks=2 run

3、磁盘IO性能测试

[root@xutest /]#sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw prepare
[root@xutest /]#sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw run
[root@xutest /]#sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw cleanup

上述参数指定了最大创建8个线程,创建的文件总大小为4G,文件读写模式为随机读。

4、内存测试

[root@xutest /]#sysbench –test=memory –memory-block-size=16k –memory-total-size=2G run

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

5、OLTP测试

[root@xutest /]#sysbench –test=oltp –mysql-table-engine=myisam –oltp-table-size=1000000 \
–mysql-socket=/tmp/mysql.sock –mysql-user=test –mysql-host=localhost \
–mysql-password=test prepare

上述参数指定了本次测试的表存储引擎类型为 myisam,指定了表最大记录数为 1000000,其他参数就很好理解了,主要是指定登录方式。测试 OLTP 时,可以自己先创建数据库或者自己用参数 –mysql-db 来指定其他数据库。–mysql-table-engine 还可以指定为 innodb 等 MySQL 支持的表存储引擎类型.

wget http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz
cd libtool-2.2.6
./configure –prefix=/usr
make && make install

yum groupinstall ‘X Window System’

########################################################### code

1、cpu性能测试

Intel(R) Xeon(TM) CPU 2.80GHz 双核*2 mem:8g
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@web-node02 ~]# sysbench –test=cpu –cpu-max-prime=20000 run
sysbench 0.4.10: multi-threaded system evaluation benchmark

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

Doing CPU performance benchmark

Threads started!

Maximum prime number checked in CPU test: 20000

Test execution summary:
total time: 74.2254s | 72.0945s
total number of events: 10000 | 10000
total time taken by event execution: 74.2183 | 72.0877
per-request statistics:
min: 6.10ms | 6.10ms
avg: 7.42ms | 7.21ms
max: 15.23ms | 16.31ms
approx. 95 percentile: 11.91ms | 11.78ms

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

2、线程测试
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@web-node02 ~]# sysbench –test=threads –num-threads=64 –thread-yields=100 –thread-locks=2 run
sysbench 0.4.10: multi-threaded system evaluation benchmark

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

Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.

Test execution summary:
total time: 3.9995s
total number of events: 10000
total time taken by event execution: 255.4787
per-request statistics:
min: 0.25ms
avg: 25.55ms
max: 264.61ms
approx. 95 percentile: 93.30ms

Threads fairness:
events (avg/stddev): 156.2500/18.99
execution time (avg/stddev): 3.9919/0.00

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3、磁盘IO性能测试

[root@web-node02 test]# sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw prepare
sysbench 0.4.10: multi-threaded system evaluation benchmark

128 files, 32768Kb each, 4096Mb total
Creating files for the test…

[root@web-node02 test]# sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw run
sysbench 0.4.10: multi-threaded system evaluation benchmark

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

Extra file open flags: 0
128 files, 32Mb each
4Gb 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!
FATAL: Failed to fsync file! file: 0 errno = 22 ()
FATAL: Incorrect file discovered in request
(last message repeated 6 times)
Done.

Operations performed: 2522 Read, 1678 Write, 5248 Other = 9448 Total
Read 39.406Mb Written 26.219Mb Total transferred 65.625Mb (4.8529Mb/sec)
310.58 Requests/sec executed

Test execution summary:
total time: 13.5229s
total number of events: 4200
total time taken by event execution: 35.6801
per-request statistics:
min: 0.02ms
avg: 8.50ms
max: 211.35ms
approx. 95 percentile: 52.99ms

Threads fairness:
events (avg/stddev): 525.0000/52.47
execution time (avg/stddev): 4.4600/0.37

sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw cleanup

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

########################################################### pic

1、cpu性能测试

Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz 双核*1 mem:4g
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@pic5 ~]# sysbench –test=cpu –cpu-max-prime=20000 run
sysbench 0.4.10: 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: 59.3203s | 59.3493s
total number of events: 10000 | 10000
total time taken by event execution: 59.3157 | 59.3447
per-request statistics:
min: 5.93ms | 5.93ms
avg: 5.93ms | 9.93ms
max: 9.91ms | 9.92ms
approx. 95 percentile: 5.93ms | 9.94ms

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

2、线程测试
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@pic5 ~]# sysbench –test=threads –num-threads=64 –thread-yields=100 –thread-locks=2 run
sysbench 0.4.10: multi-threaded system evaluation benchmark

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

Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.

Test execution summary:
total time: 1.8670s
total number of events: 10000
total time taken by event execution: 119.0826
per-request statistics:
min: 0.22ms
avg: 11.91ms
max: 503.34ms
approx. 95 percentile: 65.63ms

Threads fairness:
events (avg/stddev): 156.2500/86.64
execution time (avg/stddev): 1.8607/0.00
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3、磁盘IO性能测试

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@pic5 ~]# sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw prepare
sysbench 0.4.10: multi-threaded system evaluation benchmark

128 files, 32768Kb each, 4096Mb total
Creating files for the test…

[root@pic5 ~]# sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw run
sysbench 0.4.10: multi-threaded system evaluation benchmark

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

Extra file open flags: 0
128 files, 32Mb each
4Gb 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: 6001 Read, 3999 Write, 12800 Other = 22800 Total
Read 93.766Mb Written 62.484Mb Total transferred 156.25Mb (3.5212Mb/sec)
225.36 Requests/sec executed

Test execution summary:
total time: 44.3742s
total number of events: 10000
total time taken by event execution: 175.0314
per-request statistics:
min: 0.01ms
avg: 17.50ms
max: 572.04ms
approx. 95 percentile: 147.49ms

Threads fairness:
events (avg/stddev): 1250.0000/240.44
execution time (avg/stddev): 21.8789/0.99

sysbench –test=fileio –num-threads=8 –file-total-size=4G –file-test-mode=rndrw cleanup