mysql数据库性能测试工具比较多,本文主要讲下sysbench测试mysql。
sysbench在0.5以前是不支持多表测试,0.5版本以后才支持,因为我的mysql是自己编译的,yum安装sysbench0.5找不到mysql类库,所以采用了,sysbench-0.4.12加sysbench-db-scripts这个升级包,使其支持多表测试。
#下载sysbench-0.4.12源码包
#安装编译包
yum install libtool
#下载升级包源码要通过bzr获取
#bzr branch lp:~vadim-tk/sysbench/sysbench-db-scripts
./autogen.sh
cp /usr/bin/libtool .
./configure –prefix=/tmp/sysbench-0.4.12 –with-mysql –with-mysql-includes=/u01/mysql/include/ –with-mysql-libs=/u01/mysql/lib ;
make -j 8
sudo make install
cd /tmp/sysbench-0.4.12/bin/
然后在mysql中创建sbtest库
#导数据 耗时较长
./sysbench --test=tests/db/oltp.lua --max-time=30 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-table-engine=innodb --oltp-table-size=30000000 --num-threads=100 --mysql-socket=/tmp/mysql.sock --oltp-read-only=on prepare
#开始测试
./sysbench --test=tests/db/oltp.lua --max-time=30 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-table-engine=innodb --oltp-table-size=30000000 --num-threads=100 --mysql-socket=/tmp/mysql.sock --oltp-read-only=on run
#清除数据
./sysbench --test=tests/db/oltp.lua --max-time=30 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-table-engine=innodb --oltp-table-size=30000000 --num-threads=100 --mysql-socket=/tmp/mysql.sock --oltp-read-only=on cleanup
#数据结果分析
Number of threads: 1
Report intermediate results every 5 second(s)
Initializing random number generator from seed (42).
Threads started!
[ 5s] threads: 1, tps: 508.41, reads/s: 7119.12, writes/s: 0.00 response time: 2.16ms (99%)
[ 10s] threads: 1, tps: 506.40, reads/s: 7090.81, writes/s: 0.00 response time: 2.12ms (99%)
...
[ 290s] threads: 1, tps: 495.18, reads/s: 6930.18, writes/s: 0.00 response time: 2.22ms (99%)
[ 295s] threads: 1, tps: 496.24, reads/s: 6949.79, writes/s: 0.00 response time: 2.21ms (99%)
[ 300s] threads: 1, tps: 496.59, reads/s: 6951.62, writes/s: 0.00 response time: 2.22ms (99%)
OLTP test statistics:
queries performed:
read: 2102646
write: 0
other: 300378
total: 2403024
transactions: 150189 (497.31 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 2102646 (6962.39 per sec.)
other operations: 300378 (994.63 per sec.)
General statistics:
total time: 302.0008s
total number of events: 150189
total time taken by event execution: 301.8486s
response time:
min: 1.70ms
avg: 2.01ms
max: 4.30ms
approx. 99 percentile: 2.22ms
Threads fairness:
events (avg/stddev): 150189.0000/0.00
execution time (avg/stddev): 301.8486/0.00
从结果来看,在300s的执行时间里,平均每秒的事务数有497个,每秒能够处理的读写请求为6962个,而平均执行时间为2ms。