近期工作需要做一个mysql的benchmark,于是就用了mysql官方推荐的性能测试工具,sysbench。这是一个功能比较全的性能测试。下面是简介:
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL。
1、sysbench安装
wget -c http://sourceforge.net/projects/sysbench/files/sysbench/0.4.12/sysbench-0.4.12.tar.gz/download
tar zxvf sysbench-0.4.12.tar.gz
如果用的不是发行版本,则需要首先运行一下
./autogen.sh
sudo ./configure --with-mysql-includes=/home/tianjin.lp/mysql55/include/ --with-mysql-libs=/home/tianjin.lp/mysql55/lib/
./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql/ --with-mysql-includes=/usr/local/mysql/include/mysql/ --with-mysql-libs=/usr/local/mysql/lib/mysql/
./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql-5.1.60/ --with-mysql-includes=/usr/local/mysql-5.1.60/include/mysql/ --with-mysql-libs=/usr/local/mysql-5.1.60/lib/mysql/
make
make install
如果运行的时候出现了:sysbench: error while loading shared libraries: libmysqlclient.so.18
则需要需要link一下mysql的so.18这个库到userlib下
sudo ln -s /home/tianjin.lp/mysql55/lib/libmysqlclient.so.18 /usr/lib64/
安装完毕
2、sysbench对于mysql的测试
① 创建 sbtest数据库 create database sbtest;
② 准备数据
/usr/local/sysbench/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-db=sbtest --mysql-user=root --mysql-password=123456 prepare
③ 测试数据
/usr/local/sysbench/bin/sysbench --num-threads=16 --max-requests=100000 --test=oltp --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-db=sbtest --mysql-user=root --mysql-password=123456 --oltp-read-only run
测试参数: 对innodb存储引擎
/usr/local/sysbench/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=192.168.0.41 --mysql-password=123456 run
/usr/local/sysbench/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=192.168.10.239 --mysql-password=123456 run
测试参数: 对innodb存储引擎,16个线程,最大查询100000
/usr/local/sysbench/bin/sysbench --test=oltp --num-threads=16 --max-requests=100000 --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=192.168.0.41 --mysql-password=123456 run
/usr/local/sysbench/bin/sysbench --test=oltp --num-threads=16 --max-requests=100000 --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=192.168.10.239 --mysql-password=123456 run
④ 清理现场
/usr/local/sysbench/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 --mysql-db=sbtest --mysql-socket=/tmp/mysql.sock cleanup
3、结果展示
Running the test with following options:Number of threads: 1000
OLTP test statistics: queries performed:
read: 140000
write: 0
other: 20000
total: 160000
transactions: 10000 (1927.30 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 140000 (26982.27 per sec.)
other operations: 20000 (3854.61 per sec.)
Test execution summary:
total time: 5.1886s
total number of events: 10000
total time taken by event execution: 113.4846
per-request statistics:
min: 1.98ms
avg: 11.35ms
max: 5159.81ms
approx. 95 percentile: 2.13ms
Threads fairness:
events (avg/stddev): 10.0000/86.94
execution time (avg/stddev): 0.1135/0.65
参考
http://liupeng.sinaapp.com/?p=31
http://database.51cto.com/art/201010/230055.htm
http://www.ningoo.net/html/2009/performance_test_tool_sysbench.html
http://wenku.baidu.com/view/df4d96f4ba0d4a7302763aa0.html
转载于:https://blog.51cto.com/ppabc/817211