Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7488533
  • 博文数量: 368
  • 博客积分: 9600
  • 博客等级: 上校
  • 技术积分: 18875
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-01 00:00
文章分类

全部博文(368)

文章存档

2017年(9)

2016年(19)

2015年(3)

2014年(6)

2013年(8)

2012年(78)

2011年(66)

2010年(135)

2009年(44)

分类: LINUX

2011-10-14 09:17:11


        sysbench是一个模块化的、跨平台、多线程基准负载情况。它主要包括以下几种方式的测试:工具

文档顺序:

一、安装

二、测试

1、cpu性能
2、磁盘io性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
        目前sysbench主要支持 ,pgsql,oracle 这3种数据库。

三、报错及注意事项

详细步骤:

一、安装
        首先,在 源码包。
        接下来,按照以下步骤安装:

tar zxf sysbench-0.4.8.tar.gz
cd sysbench-0.4.8
./configure && make && make install
strip /usr/local/bin/sysbench

        以上方法适用于 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 包来安装。
        另外,如果想要让 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,这里需要注意的是,官方网站上的参数有一处有误,即 --mysql-table-engine,官方网站上写的是 --mysql-table-type,这个应该是没有及时更新导致的。另外,指定了表最大记录数为 1000000,参数就很好理解了,主要是指定登录方式。测试 OLTP 时,可以自己先创建数据库 sbtest,或者自己用参数 --mysql-db 来指定其他数据库。--mysql-table-engine 还可以指定为 innodb 等 MySQL 支持的表存储引擎类型。

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

拿两台机器,test18CPU16G内存)和test23CPU8G内存)来做测试

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

线程测试
sysbench --test=threads --num-threads=512 --thread-yields=100 --thread-locks=2 run

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

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

5OLTP测试

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 自己生成的。

d)make的时候报如下错:

/root/zhangxy/sysbench-0.4.12/config/missing: line 46: automake-1.10: command not found
WARNING: `automake-1.10' is missing on your system.  You should only need it if
         you modified `Makefile.am', `acinclude.m4' or `configure.ac'.
         You might want to install the `Automake' and `Perl' packages.
         Grab them from any GNU archive site.

解决办法:yum -y install automake*

e)make的时候出现如下报错:

./configure: line 4063: AC_PROG_LIBTOOL: command not found

/bin/sh: ./config.status: No such file or directory
make: *** [Makefile] Error 127

解决办法:yum -y install libtool

./autogen.sh然后再编译就可以了!

2、注意事项:

JavaGG 发表于 2009-08-25 10:50

千万不要用0.8.12这个版本不为什么装不上,说找不到路径什么的

还有我装的时候老是说找不到mysqlclient.so 什么的。。

后来听说是因为mysql用rpm安装不行,,要用tar自己编译的才行。日了


转自: http://hi.baidu.com/arongdy/blog/item/f220a5d45616aa0ba18bb70d.html

阅读(5421) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~