Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2295031
  • 博文数量: 276
  • 博客积分: 5998
  • 博客等级: 大校
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 14:43
文章分类

全部博文(276)

文章存档

2014年(25)

2013年(11)

2012年(69)

2011年(167)

2010年(4)

分类: Mysql/postgreSQL

2011-09-05 15:03:45

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQLOraclePostgreSQL。以下操作都将以支持MySQL数据库为例进行。

下载源码包

网站上下载,我下载到的源码包是sysbench-0.4.12.tar.gz

环境准备

我的系统是CentOS 5.5,在进行编译安装前需要先进性相关软件的安装和更新。

首先,安装和更新gcc,否则在编译安装时会报错误:configure: error: no acceptable C compiler found in $PATH,安装命令为:yum install gcc

其次,安装和更新libtool,否则在编译安装时会报类似错误:

../libtool: line 838: X--tag=CC: command not found

../libtool: line 871: libtool: ignoring unknown tag : command not found

../libtool: line 838: X--mode=link: command not found

../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found

../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found

../libtool: line 2231: X-g: command not found

../libtool: line 2231: X-O2: command not found

../libtool: line 2231: X-rdynamic: command not found

../libtool: line 1951: X-L/usr/lib/mysql: No such file or directory

../libtool: line 2400: Xsysbench: command not found

 

Fatal server error:

Server is already active for display 0

        If this server is no longer running, remove /tmp/.X0-lock

        and start again.

 

../libtool: line 2412: Xsysbench: command not found

../libtool: line 2547: X-lmysqlclient_r: command not found

../libtool: line 2547: X-lz: command not found

../libtool: line 2547: X-lcrypt: command not found

../libtool: line 2547: X-lnsl: command not found

../libtool: line 2547: X-lm: command not found

../libtool: line 2547: X-lmygcc: command not found

../libtool: line 2547: X-lrt: command not found

../libtool: line 2547: X-lm: command not found

../libtool: line 2629: X-L/root/tool/sysbench-0.4.12/sysbench: No such file or directory

../libtool: line 2547: X-lmysqlclient_r: command not found

../libtool: line 2547: X-lz: command not found

../libtool: line 2547: X-lcrypt: command not found

../libtool: line 2547: X-lnsl: command not found

../libtool: line 2547: X-lmygcc: command not found

../libtool: line 2547: X-lrt: command not found

../libtool: line 2547: X-lm: command not found

../libtool: line 2629: X-L/root/tool/sysbench-0.4.12/sysbench: No such file or directory

../libtool: line 2547: X-lmysqlclient_r: command not found

../libtool: line 2547: X-lz: command not found

../libtool: line 2547: X-lcrypt: command not found

../libtool: line 2547: X-lnsl: command not found

../libtool: line 2547: X-lmygcc: command not found

../libtool: line 2547: X-lrt: command not found

../libtool: line 2547: X-lm: command not found

../libtool: line 5162: Xgcc -pthread "" "" -o @OUTPUT@ sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o ""  tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -L/root/tool/sysbench-0.4.12/sysbench -lmysqlclient_r -lz -lcrypt -lnsl -lmygcc -lrt -lm: No such file or directory

../libtool: line 5163: Xgcc -pthread "" "" -o @OUTPUT@ sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o ""  tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -L/root/tool/sysbench-0.4.12/sysbench -lmysqlclient_r -lz -lcrypt -lnsl -lmygcc -lrt -lm: No such file or directory

安装命令为:yum install libtool


2、

drv_mysql.c:35:19: error: mysql.h: No such file or directory

drv_mysql.c:36:26: error: mysqld_error.h: No such file or directory

这个错误有两种解决方法,根据情况来解决。

1)如果你是yum安装的mysql,那么,你只需要再装一个包。Yum install mysql-devel -y,即可解决问题。

2)如果你是源码编译安装的mysql。例如:我喜欢把mysql安装到/usr /local/mysql目录下,那么编译安装sysbench的时候使用./configure –with-mysql-includes=/usr/local/mysql/include/mysql –with-mysql-libs=/usr/local/mysql/lib/mysql

3、

如果出现大量以下错误:

../libtool: line 838: X–tag=CC: command not found

./autogen.sh && ./configure && make && make install

解决办法很简单。到sysbench解压后的目录下执行autogen.sh即可。

编译安装

准备好环境之后就可以开始进行编译安装了。

首先对压缩包进行解压:tar zxf sysbench-0.4.12.tar.gz

其次,在解压好的目录下运行命令:./autogen.sh,对环境进行清理。该操作是sysbench0.4.12独有的,不进行的话也会出现类似如上第2个错误。

然后,进行编译安装。如果MySQL是默认安装的,则直接运行如下命令进行编译安装:

./configure --build=i686-pc-linux-gnu && make && make install

其中,--build指定操作系统的类型,否则可能会出现如下错误:

checking build system type... Invalid configuration `i686-pc-linux-': machine `i686-pc-linux' not recognized

configure: error: /bin/sh config/config.sub i686-pc-linux- failed

如果MySQL不是安装在标准默认目录下,那么就还需要指定MySQL的路径。如MySQL安装在/var/mysql下,则运行如下命令进行编译安装:

./configure --build=i686-pc-linux-gnu –with-mysql-includes=/var/mysql/include –with-mysql-libs=/var/mysql/lib && make && make install

如果需要sysbench支持Oracle或者PostgreSQL的话,还需要在编译时加上--with-pgsql或者--with-oracle

 

进行测试

 

NinGoo:/u01/sysbench/bin>$sysbench
Missing required command argument.
Usage:
  sysbench [general-options]... --test= [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= 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指定每个线程的锁数量。

数据库性能测试

 注意:在高于100时的并发量时 不要用 --oltp-skip-trx=on 否则有可能出现Duplicate entry 'xxx' for key 'PRIMARY错误

首先,准备测试数据

# sysbench --test=oltp --mysql-host=127.0.0.1   --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=innodb --mysql-engine-trx=yes  --oltp-table-size=1000000 --max-requests=4000  --mysql-user=root --mysql-socket=/data/mysqldata5.5/mysql.sock --mysql-port=3307  --num-threads=1000 prepare

然后执行测试

# sysbench --test=oltp --mysql-host=127.0.0.1   --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=innodb --mysql-engine-trx=yes  --oltp-table-size=1000000 --max-requests=4000  --mysql-user=root --mysql-socket=/data/mysqldata5.5/mysql.sock --mysql-port=3307  --num-threads=1000  run

最后清理测试数据

# sysbench --test=oltp --mysql-host=127.0.0.1   --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=innodb --mysql-engine-trx=yes  --oltp-table-size=1000000 --max-requests=4000  --mysql-user=root --mysql-socket=/data/mysqldata5.5/mysql.sock --mysql-port=3307  --num-threads=1000 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查看。
阅读(2692) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~