sysbench安装
sysbench是一款开源的多线程性能测试工具,
可以执行CPU/内存/线程/IO/数据库等方面的性能测试。
数据库目前支持MySQL/Oracle/PostgreSQL。
安装:
首先,安装和更新gcc,安装命令为:
yum install gcc
(如果未安装,在真正编译安装sysbench时会报误:configure: error: no acceptable C compiler found in $PATH)
其次,安装和更新libtool,安装命令为:
yum install libtool
(如果未安装,在真正编译安装sysbench时会报误:...../libtool: line 838: X--tag=CC: command not found.....)
第三,需要到mysql官网上下载安装
MySQL-devel-xxx.rpm
MySQL-shared-xxx.rpm
MySQL-client-xxx.rpm
下载地址:http://www.mysql.com/downloads/
请选择相应的mysql版本(x占位使用)
(如果未安装,在真正编译安装sysbench时会报误:类似找不到mysql相关的库文件xxx.so/xxx.a错误)
第四,正式开始安装sysbench
在 http://sourceforge.net/projects/sysbench 下载源码包。(我下载的版本是0.4.12)
tar zxf sysbench-0.4.12.tar.gz cd sysbench-0.4.12 ./autogen.sh ./configure && make && make install
以上方法适用于 MySQL 安装在标准默认目录下的情况,
如果 MySQL 并不是安装在标准目录下的话,那么就需要自己指定 MySQL 的路径了。
比如我的 MySQL 喜欢自己安装在 /usr/local/mysql 下,则按照以下方法编译:
./autogen.sh ./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
如果mysql使用的是yum 工具安装,则按照以下方法编译:
./autogen.sh ./configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib/mysql && make && make install
如果mysql使用的是yum 工具安装,且是64位的mysql,则按照以下方法编译:
./autogen.sh ./configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql && make && make install
另外,如果想要让 sysbench 支持 pgsql/oracle 的话,就需要在编译的时候加上参数
--with-pgsql或者--with-oracle这2个参数默认是关闭的,只有 MySQL 是默认支持的。
使用命令
sysbench --help
查看是否安装成功,如果打印如下信息,证明安装OK:
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.
OK大功告成,我在安装的时候遇到了N多问题,大多是mysql库文件找不到,最后发现mysql使用运维人员使用的yum安装的,而且是64位的,导致我配置的路径总是错误,^_^
使用:
1.CPU的基准测试:
测试CPU计算素数的时间:
sysbench --test=cpu --cpu-max-prime=20000 run
输出结果:
sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 1 Doing CPU performance benchmark Threads started! Done. Maximum prime number checked in CPU test: 20000 Test execution summary: total time: 22.0217s total number of events: 10000 total time taken by event execution: 22.0180 per-request statistics: min: 2.18ms avg: 2.20ms max: 4.27ms approx. 95 percentile: 2.20ms Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 22.0180/0.00
总耗时total time: 22.0217s