SysBench压力测试
December 15th, 2010
SysBench安装
下载SysBench
[root@localhost opt]# wget http://downloads.sourceforge.net/project/sysbench/sysbench/0.4.12/sysbench-0.4.12.tar.gz
安装SysBench
[root@localhost opt]# tar zxvf sysbench-0.4.12.tar.gz
[root@localhost sysbench-0.4.12]# ./configure --prefix=/opt/sysbench \
--with-mysql-includes=/mysql/include/mysql \
--with-mysql-libs=/mysql/lib/mysql
[root@localhost sysbench-0.4.12]#make && make install
出现以下错误:
../libtool: line 835: X--tag=CC: command not found
../libtool: line 868: libtool: ignoring unknown tag : command not found
../libtool: line 835: X--mode=link: command not found
../libtool: line 1001: *** Warning: inferring the mode of operation is deprecated.: command not found
../libtool: line 1002: *** Future versions of Libtool will require --mode=MODE be specified.: command not found
../libtool: line 2228: X-D_THREAD_SAFE: command not found
../libtool: line 2228: X-g: command not found
../libtool: line 2228: X-O2: command not found
../libtool: line 1948: X-L/usr/local/mysql/lib: No such file or directory
../libtool: line 2397: Xsysbench: command not found
解决办法: 修改configure.ac文件,注释掉 AC_PROG_LIBTOOL,添加上 AC_PROG_RANLIB
[root@localhost sysbench-0.4.12]# vi configure.ac
#AC_PROG_LIBTOOL
AC_PROG_RANLIB
再执行
[root@localhost sysbench-0.4.12]# ./autogen.sh
重新安装,一切OK
[root@localhost sysbench-0.4.12]# ./configure --prefix=/opt/sysbench --with-mysql-includes=/mysql/include/mysql --with-mysql-libs=/mysql/lib/mysql
[root@localhost sysbench-0.4.12]# make && make install
SysBench压力测试
1、cpu测试
sysbench --test=cpu --cpu-max-prime=20000 run
2、线程测试
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
3、磁盘IO性能测试
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup
上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读。
4、内存测试
sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=4G run
上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。
5、Mutex测试
sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
6、OLTP测试
sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --db-driver=mysql prepare
sysbench --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mysql-table-engine=innodb --oltp-table-size=1000000 --db-ps-mode=disable --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --num-threads=16 --max-time=600 run
sysbench --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mysql-table-engine=innodb --oltp-table-size=1000000 --db-ps-mode=disable --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --num-threads=16 --max-time=600 --oltp-read-only run
sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --db-driver=mysql cleanup
测试 OLTP 时,要自己先创建数据库 sbtest否则提示找不到数据库,也可以用参数 --mysql-db 来指定使用其他数据库 。
[root@localhost bin]# ./sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-host=127.0.0.1 --mysql-user=chaos --mysql-password=123456 --mysql-socket=/mysql/mysql.sock prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
FATAL: unable to connect to MySQL server, aborting...
FATAL: error 1049: Unknown database 'sbtest'
FATAL: failed to connect to database server!
测试结果
CPU性能测试:
[root@localhost bin]# ./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: 45.8865s
total number of events: 10000
total time taken by event execution: 45.8828
per-request statistics:
min: 4.58ms
avg: 4.59ms
max: 4.68ms
approx. 95 percentile: 4.59ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 45.8828/0.00
线程测试:
[root@localhost bin]# ./sysbench --test=threads --num-threads=64 --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: 64
Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.
Test execution summary:
total time: 2.0729s
total number of events: 10000
total time taken by event execution: 132.4626
per-request statistics:
min: 0.04ms
avg: 13.25ms
max: 116.38ms
approx. 95 percentile: 50.31ms
Threads fairness:
events (avg/stddev): 156.2500/16.77
execution time (avg/stddev): 2.0697/0.00
IO性能测试:
[root@localhost bin]# ./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
Creating files for the test...
[root@localhost bin]# ./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
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
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: 5996 Read, 4004 Write, 12803 Other = 22803 Total
Read 93.688Mb Written 62.562Mb Total transferred 156.25Mb (9.8301Mb/sec)
629.13 Requests/sec executed
Test execution summary:
total time: 15.8951s
total number of events: 10000
total time taken by event execution: 14.4041
per-request statistics:
min: 0.01ms
avg: 1.44ms
max: 270.11ms
approx. 95 percentile: 0.02ms
Threads fairness:
events (avg/stddev): 625.0000/129.93
execution time (avg/stddev): 0.9003/0.24
[root@localhost bin]# ./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...
内存测试:
[root@localhost bin]# ./sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=4G run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Doing memory operations speed test
Memory block size: 8K
Memory transfer size: 4096M
Memory operations type: write
Memory scope type: global
Threads started!
Done.
Operations performed: 524288 (648554.23 ops/sec)
4096.00 MB transferred (5066.83 MB/sec)
Test execution summary:
total time: 0.8084s
total number of events: 524288
total time taken by event execution: 7.2785
per-request statistics:
min: 0.00ms
avg: 0.01ms
max: 4.33ms
approx. 95 percentile: 0.01ms
Threads fairness:
events (avg/stddev): 32768.0000/4387.59
execution time (avg/stddev): 0.4549/0.02
Mutex测试:
[root@localhost bin]# ./sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 0.1577s
total number of events: 16
total time taken by event execution: 2.1000
per-request statistics:
min: 73.13ms
avg: 131.25ms
max: 145.63ms
approx. 95 percentile: 145.56ms
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.1313/0.02
数据库测试:
[root@localhost bin]# ./sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --db-driver=mysql prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
[root@localhost bin]# ./sysbench --mysql-db=sbtest --max-requests=0 --test=oltp --mysql-engine-trx=yes --mysql-table-engine=innodb --oltp-table-size=1000000 --db-ps-mode=disable --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --num-threads=16 --max-time=600 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: 16
Doing OLTP test.
Running mixed OLTP 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 15 times)
Done.
OLTP test statistics:
queries performed:
read: 298466
write: 106595
other: 42638
total: 447699
transactions: 21319 (35.51 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 405061 (674.64 per sec.)
other operations: 42638 (71.01 per sec.)
Test execution summary:
total time: 600.4126s
total number of events: 21319
total time taken by event execution: 9602.9898
per-request statistics:
min: 47.43ms
avg: 450.44ms
max: 897.43ms
approx. 95 percentile: 518.83ms
Threads fairness:
events (avg/stddev): 1332.4375/2.09
execution time (avg/stddev): 600.1869/0.12
[root@localhost bin]# ./sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=chaos --mysql-host=127.0.0.1 --mysql-socket=/mysql/mysql.sock --mysql-password=123456 --db-driver=mysql cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark
Dropping table 'sbtest'...
Done.