努力学习,努力分享,努力.....在努力..努力离开..
分类: Mysql/postgreSQL
2014-03-20 11:13:34
原文地址:sysbench压力测试工具简介和使用(二) 作者:vcdog
CPU: 24核心线程数,Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
MEM: 64G,8*8G=64G
DISK: 15000转/秒
创建初始化fileio文件:
[root@db-master sysbench]# sysbench --test=fileio --file-num=16 --file-total-size=2G prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
16 files, 131072Kb each, 2048Mb total
Creating files for
the test...
接下来开始对这些文件进行测试,使用16个线程随机读进行测试结果如下:
[root@db-master sysbench]# 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.说明服务器的硬件配置还不错。
测试结束后,记得执行cleanup,以确保测试所产生的文件都已删除:
[root@db-master sysbench]# sysbench --test=fileio --file-num=16 --file-total-size=2G cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark
Removing test files...
如果需要测试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), kevin@gmail.com
# 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=$blksize run|tee -a sysbench-size-$size-mo
de-$mode-threads-$threads-blksz-$blksize 2>&1
done
done
sysbench --test=fileio --file-total-size=$size cleanup
done
done
done
-- 脚本运行后,在当前目录下会生成如下文件:
对于mysql的OLTP测试,和file一样,同样需要经历prepare,run,cleanup三个阶段。prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为
sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:
[root@db-master sysbench]# 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=test prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
Creating table 'sbtest'...
Creating 10 records in table 'sbtest'...
接下来对上面产生的表进行oltp的测试:
[root@db-master sysbench]# 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.sock run > result.log
参数说明:
--max-time=3600 指定测试时长为1小时
--mysql-db=test 指定测试的数据库名
[root@db-master sysbench]# cat result.log
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.
Doing OLTP test.
Running mixed OLTP test
Using Uniform distribution
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: 137346874
write: 49052449
other: 19620980
total: 206020303
transactions: 9810489 (2725.13 per sec.)
deadlocks: 2 (0.00 per sec.)
read/write requests: 186399323 (51777.50 per sec.)
other operations: 19620980 (5450.26 per sec.)
Test execution summary:
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的测试只是基准测试,并不能代表实际企业环境下的性能指标。