sysbench性能测试工具

来源:互联网 发布:usb端口定义 编辑:程序博客网 时间:2024/05/21 09:20

sysbench是一个模块化的、跨平台、多线程基准,主要用于评估测试各种不同系统参数下的数据库负载情况。它主要包括以下几种方式的测试工具。

 

一、安装

        首先,在 http://sourceforge.net/projects/sysbench 下载源码包。

        接下来,按照以下步骤安装:

tar zxf sysbench-0.4.12.tar.gz

cd sysbench-0.4.12

./configure && make && make install

        以上方法适用于 MySQL 安装在标准默认目录下的情况,如果 MySQL 并不是安装在标准目录下的话,那么就需要自己指定 MySQL 的路径了。比如我的 MySQL 喜欢自己安装在 /usr/local/mysql 下,则按照以下方法编译:

 

./configure --with-mysql-includes=/usr/local/mysql/include/mysql --with-mysql-libs=/usr/local/mysql/lib/mysql && make && make install

     当然了,用上面的参数编译的话,就要确保你的 MySQL lib目录下有对应的 so 文件,如果没有,可以自己下载 devel 或者 share 包来安装(推荐使用MySQL的源码包安装)。

        另外,如果想要让 sysbench 支持 pgsql/oracle 的话,就需要在编译的时候加上参数

--with-pgsql

或者

--with-oracle

        这2个参数默认是关闭的,只有 MySQL 是默认支持的。

 

二、使用方法

        编译成功之后,就要开始测试各种性能了,测试的方法官网网站上也提到一些,但涉及到 OLTP 测试的部分却不够准确。在这里我大致提一下:

1、cpu性能测试 

sysbench --test=cpu --cpu-max-prime=20000 run

        cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值。

 

2、线程测试 

sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run


3、磁盘IO性能测试 

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup

        上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读(rndrw)。

 

4、内存测试 

sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run

        上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。

 

5、OLTP测试 

sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=test --mysql-host=localhost --mysql-password=test prepare

        上述参数指定了本次测试的表存储引擎类型为 myisam,另外,指定了表最大记录数为 1000000,其他参数就很好理解了,主要是指定登录方式。测试 OLTP 时,可以自己先创建数据库 sbtest,或者自己用参数 --mysql-db 来指定其他数据库。--mysql-table-engine 还可以指定为 innodb 等 MySQL 支持的表存储引擎类型。

 

测试的时候注意thread数大于两倍CPU数,测试文件大小大于5倍内存大小。

 

拿两台机器,test1(8CPU,16G内存)和test2(3CPU,8G内存)来做测试

 

1、 cpu性能测试

sysbench --test=cpu --num-threads=32 --cpu-max-prime=90000 run

cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 90000,

 

root :/root>#sysbench --test=cpu --num-threads=32 --cpu-max-prime=90000 run

 

2、 线程测试

sysbench --test=threads --num-threads=512 --thread-yields=100 --thread-locks=2 run

 

thread-locks小于线程数除以2,lock越少,处理时间越长。

 

test1: sysbench --test=threads --num-threads=512 --thread-yields=100 --thread-locks=2 run

 

3、磁盘IO性能测试

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run

sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup上述参数指定了最大创建16个线程,创建的文档总大小为3G,文档读写模式为随机读。

 

CD到空间足够的文件系统,执行命令等待创建

 

test1:/root>#sysbench --test=fileio --num-threads=64 --file-total-size=12G --file-test-mode=rndrw prepare

 

我们看到两台机器的速度差好多,一个64M/S,一个19M/S.第二台估计有问题,需要找找原因。测试完后记得删除数据,否则会占用空间。

 

sysbench --test=fileio --num-threads=64 --file-total-size=12G --file-test-mode=rndrw cleanup

 

4、内存测试

 

sysbench --test=memory --memory-block-size=8192 --memory-total-size=4G run上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。

 

test1:/root>#sysbench --test=memory --num-threads=32 --memory-block-size=8192 --memory-total-size=512G run

 

5、OLTP测试

 

     1 、准备数据

# sysbench --debug=off --test=oltp --mysql-host=10.15.2.137 --mysql-user=test --mysql-password=test --oltp-table-size=1000000 --mysql-db=test --oltp-table-name=stest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes prepare

 

      2、测试

# sysbench --debug=off --test=oltp --mysql-host=10.15.2.137 --mysql-user=test --mysql-password=test --oltp-table-size=1000000 --mysql-db=test --oltp-table-name=stest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes run

 

       3、删除数据

# sysbench --debug=off --test=oltp --mysql-host=10.15.2.137 --mysql-user=test --mysql-password=test --oltp-table-size=1000000 --mysql-db=test --oltp-table-name=stest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes cleanup

 

指定了表最大记录数为 1000000,其他参数就很好理解了,主要是指定登录方式。测试 OLTP 时,能够自己先创建数据库 sbtest,或自己用参数 --mysql-db 来指定其他数据库。--mysql-table-engine 还能够指定为 innodb 等 MySQL 支持的表存储引擎类型。

 

三、报错及注意事项:

 

1、安装报错:

 

a) 毕后,如果在运行时出现下面的错误提示:

 

sysbench: error while loading shared libraries: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

 

使用下面的命令查看libmysqlclient_r.so.16是否存在

 

[root@node2 sysbench-0.4.8]# find / -name "libmysqlclient_r.so.16" -print

 

/usr/local/lib/mysql/libmysqlclient_r.so.16

 

结果显示是存在的,那么我们需要做个链接

 

[root@node2 sysbench-0.4.8]# ln -s /usr/local/lib/mysql/libmysqlclient_r.so.16 /lib/libmysqlclient_r.so.16

 

如果没有,可以自己下载 devel 或者 share 包来安装。

 

b)# make 时报错:

 

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

 

是因为找不到mysql 的头文件,只要 --with-mysql-includes= 确定好路径就可以了我的应该是 ./configure --with-mysql-includes=/usr/local/mysql/include/mysql --with-mysql-libs=/usr/local/mysql/lib/mysql     

 

c) # make 时报错:

 

../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 1951: X-L/usr/local/mysql/lib/mysql/: No such file or directory

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

 

(1) 方法 :只要先运行一次autogen.sh,然后再configure,make就可以了,作者的主页有说明的

 

(2) 方法:是因为libtool 工具版本太旧。 安装一个新的版本,然后覆盖掉sysbench 自己生成的。

0 0
原创粉丝点击