sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。关于这个项目的详细介绍请看:http://sysbench.sourceforge.net。
它主要包括以下几种方式的测试:
1、cpu性能
2、磁盘io性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
目前sysbench主要支持 MySQL,pgsql,oracle 这3种数据库。
一、安装
首先,在 http://sourceforge.net/projects/sysbench 下载源码包
但安装过程一波三折,各种不顺
安装不走如下;
tar zxf sysbench-0.4.12.tar.gz
cd sysbench-0.4.12
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
Server terminated with error (1). Closing log file.
../libtool: line 2415: Xsysbench: command not found
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/root/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/root/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
报错了,各种搜索后
表示libtool版本低
cp /usr/bin/libtool /path/to/sysbench_source/
即拷贝系统的libtool到sysbench的源码目录下即可解决以上问题
另外,如果想要让 sysbench 支持 pgsql/oracle 的话,就需要在编译的时候加上参数
--with-pgsql
或者
--with-oracle
这2个参数默认是关闭的,只有 MySQL 是默认支持的。
[root@zgqiang sysbench-0.4.12]# cp /usr/bin/libtool .
cp:是否覆盖"./libtool"? y
[root@zgqiang sysbench-0.4.12]# make && make install
正确编译通过
[root@zgqiang sysbench-0.4.12]# sysbench
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@zgqiang sysbench-0.4.12]# vim /etc/profile
[root@zgqiang sysbench-0.4.12]# source /etc/profile
[root@zgqiang sysbench-0.4.12]# sysbench
Missing required command argument.
Usage:
sysbench [general-options]... --test=<test-name> [test-options]... command
General options:
--num-threads=N number of threads to use [1]
--max-requests=N limit for total number of requests [10000]
--max-time=N limit for total execution time in seconds [0]
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
--thread-stack-size=SIZE size of stack per thread [32K]
--init-rng=[on|off] initialize random number generator [off]
--test=STRING test to run
--debug=[on|off] print more debugging info [off]
--validate=[on|off] perform validation checks where possible [off]
--help=[on|off] print help and exit
--version=[on|off] print version and exit
Compiled-in tests:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
oltp - OLTP test
Commands: prepare run cleanup help version
See 'sysbench --test=<name> help' for a list of options for each test.
运行正常了
进行测试
编译安装成功后就可以开始进行性能测试了。测试的方法和选项很多,这里大致介绍一下相关的命令和选项。
CPU性能测试
sysbench --test=cpu --cpu-max-prime=5000 run
CPU的性能测试主要通过素数的运算来进行,--cpu-max-prime用来选项指定最大的素数,具体参数可以根据CPU的性能来设置。
内存性能测试
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
--memory-block-size指定每个block的大小,--memory-total-size指定总的传输量,另外还有其他选项,可通过命令sysbench –test=memory help进行查看。
磁盘I/O性能测试
首先生成需要测试的文件
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 prepare
然后执行测试
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 run
最后清理测试文件
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 cleanup
--num-threads指定最大创建的线程数,--file-num指定文件数目,--file-taotal-size指定创建的文件总大小,--file-test-mode指定文件读写模式,rndrw为随机读,--file-rw-ratio指定读写比率。另外还有更多的选项可以通过命令sysbench –test=fileio help进行查看。
线程测试
sysbench --test=threads --num-threads=32 --thread-yields=100 --thread-locks=2 run
--num-threads指定线程数,--thread-yield指定每个请求的压力,--thread-locks指定每个线程的锁数量。
数据库性能测试
首先,准备测试数据
sysbench --test=oltp --mysql-host=server1 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=MyISAM --oltp-table-size=1000000 prepare
然后执行测试
sysbench --test=oltp --mysql-host=server1 --mysql-port=3306 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=MyISAM --mysql-engine-trx=no --oltp-skip-trx=on --oltp-table-size=1000000 --max-requests=1000 --num-threads=100 run
最后清理测试数据
sysbench --test=oltp --mysql-host=server1 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest cleanup
--mysql-host指定使用的MySQL服务器的地址,--mysql-user指定连接MySQL的用户名,--mysql-password指定密码,--mysql-db指定使用的数据库,--oltp-table-name指定使用的表,--mysql-table-engine指定表所使用的数据库引擎,--mysql-engine-trx说明使用的数据库引擎是否是事务的,--oltp-skip-trx指定是否忽略事务语句(BEGIN/COMMIT),--oltp-table-size指定数据表中的记录数,--max-requests指定最大请求数,--num-threads指定线程数,其他更多的选项可以使用命令sysbench –test=oltp help查看。