白天和黑夜只交替没交换无法想像对方的世界
分类: mysql/postgresql
2014-02-28 13:34:34
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的测试只是基准测试,并不能代表实际企业环境下的性能指标。