加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sysbench的安装和使用

发布时间:2020-12-13 17:51:18 所属栏目:百科 来源:网络整理
导读:sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行。 下载源码包 在http://sourceforge.net/pr

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

下载源码包

在http://sourceforge.net/projects/sysbench/网站上下载,我下载到的源码包是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

编译安装

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

首先对压缩包进行解压: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。

进行测试

编译安装成功后就可以开始进行性能测试了。测试的方法和选项很多,这里大致介绍一下相关的命令和选项。

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查看。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读