sysbench压力测试工具使用:
2.1 测试数据库服务器的硬件配置信息如下:
CPU: 24核心线程数,Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
MEM: 64G,8*8G=64G
DISK: 15000转/秒
2.2 对磁盘IO性能的测试:
2.2.1 创建fileio文件
创建初始化fileio文件:
[root@db-mastersysbench]#sysbench --test=fileio --file-num=16 --file-total-size=2G prepare
sysbench0.4.12: multi-threaded system evaluationbenchmark
16 files, 131072Kbeach, 2048Mb total
Creating files forthe test...
2.2.1 开始fileio测试
接下来开始对这些文件进行测试,使用16个线程随机读进行测试结果如下:
[root@db-mastersysbench]#sysbench --test=fileio --file-total-size=2G --file-test-mode=rndrd--max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on--file-num=16 --file-extra-flags=direct --file-fsync-freq=0--file-block-size=16384 run
可以看到随机读取的性能为75.988Mb/sec,随机读的IOPS为4863.25 Requests/sec.说明服务器的硬件配置还不错。
2.2.3 测试完成执行cleanup
测试结束后,记得执行cleanup,以确保测试所产生的文件都已删除:
[root@db-mastersysbench]# sysbench--test=fileio --file-num=16 --file-total-size=2G cleanup
sysbench0.4.12: multi-threaded system evaluationbenchmark
Removing testfiles...
如果需要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,并且还可能需要测试不同的线程和不同的文件块下磁盘的性能表现,这时,可以使用如下脚本达到测试目的。
测试脚本内容如下:
#!/bin/bash
#==============================================================================
#
# FILE: sysbench_auto.sh
#
# USAGE: ./sysbench_auto.sh
#
# DESCRIPTION: This file is sysbench_auto.sh
# AUTHOR: Kevin Lu (kevin), [email protected]
# ORGANIZATION: cmcc
# CREATED: 02/26/2014 17:35
# REVISION: v1.0.1
#==============================================================================
for size in {8G,64G}
do
for mode in{seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}
do
for blksize in {4096,16384}
do
sysbench --test=fileio --file-num=64--file-total-size=$size prepare
for threads in {1,4,8,16,32}
do
echo "=============testing $blksize in$threads threads"
echo PARAS $size $mode $threads $blksize> sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize
for i in {1,2,3}
do
sysbench --test=fileio--file-total-size=$size --file-test-mode=$mode --max-time=180--max-requests=100000 --num-threads=$threads --
init-rng=on --file-num=64--file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksizerun|tee -a sysbench-size-$size-mo
de-$mode-threads-$threads-blksz-$blksize2>&1
done
done
sysbench --test=fileio--file-total-size=$size cleanup
done
done
done
-- 脚本运行后,在当前目录下会生成如下文件:
3.1 对mysql事务型OLTP的测试:
3.1.1 prepare准备阶段
对于mysql的OLTP测试,和file一样,同样需要经历prepare,run,cleanup三个阶段。prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为
sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:
[root@db-mastersysbench]#sysbench --test=oltp --oltp-table-size=80000000 --db-driver=mysql--mysql-socket=/data/mysqlsoft3307/mysql.sock --mysql-user=dba_manager --mysql-password='111111' --mysql-db=testprepare
sysbench0.4.12: multi-threaded system evaluationbenchmark
Creating table'sbtest'...
Creating 10records in table 'sbtest'...
3.1.2 run运行测试
接下来对上面产生的表进行oltp的测试:
[root@db-mastersysbench]#sysbench --test=oltp --oltp-table-size=80000000 --oltp-read-only=off--init-rng=on --num-threads=16 --max-requests=0 --oltp-dist-type=uniform--max-time=3600 --mysql-user=dba_manager --mysql-password='111111' --db-driver=mysql --mysql-socket=/data/mysqlsoft3307/mysql.sockrun > result.log
参数说明:
--max-time=3600 指定测试时长为1小时
--mysql-db=test 指定测试的数据库名
[root@db-mastersysbench]#cat result.log
sysbench0.4.12: multi-threaded system evaluationbenchmark
Running the testwith following options:
Number of threads:16
Initializingrandom number generator from timer.
Doing OLTP test.
Running mixed OLTPtest
Using Uniformdistribution
Using"BEGIN" for starting transactions
Using auto_inc onthe id column
Threads started!
Time limitexceeded, exiting...
(last messagerepeated 15 times)
Done.
OLTP teststatistics:
queries performed:
read: 137346874
write: 49052449
other: 19620980
total: 206020303
transactions: 9810489 (2725.13 persec.)
deadlocks: 2 (0.00 per sec.)
read/write requests: 186399323 (51777.50 per sec.)
other operations: 19620980 (5450.26 per sec.)
Test executionsummary:
total time: 3600.0060s
total number of events: 9810489
total time taken by event execution:57542.1464
per-request statistics:
min: 3.00ms
avg: 5.87ms
max: 212.09ms
approx. 95 percentile: 8.44ms
Threads fairness:
events (avg/stddev): 613155.5625/1486.47
execution time (avg/stddev): 3596.3842/0.01
以上测试结果显示了很多操作的详细信息,transactions代表测试结果的评判标准即TPS,上述测试结果是 2725.13 per sec.
可以对数据库进行调优后,再使用sysbench对OLTP进行测试,看看TPS是不是会有所提高。
注意:sysbench的测试只是基准测试,并不能代表实际企业环境下的性能指标。