Super Smack 是一个强大的压力测试工具,支持 MySQL, PostgreSQL, Oracle。最开始的版本是由Sasha Pachev写成,由Jeremy Zawodny在维护,而现在,是
Tony Bourke在维护,根据 Tony Bourke 的 开发 log 来看,2005-08-30 后,super smack 就已经停止发布新的版本,但这并不妨碍我们现在继续使用它(这个工具的开发者和维护者很伟大)。
安装
安装有点点麻烦,主要是编译时会出现一些问题。
1
2
3
4
5
|
[root@localhost tmp]
# wget http://vegan.net/tony/supersmack/super-smack-1.3.tar.gz
[root@localhost tmp]
# tar xvzf super-smack-1.3.tar.gz
[root@localhost super-smack-1.3]
# ./configure --prefix=/usr/local/super-smack --with-mysql --with-mysql-lib=/usr/local/mysql/lib/mysql --with-mysql-include=/usr/local/mysql/include/mysql
[root@localhost super-smack-1.3]
# make
[root@localhost super-smack-1.3]
# make install
|
说明
1 编译时,必须指定它所支持的数据库管理系统,否则会报如下错误。
...... configure: error:You should include support for at least one database!Reconfigure with one or more of:--with-mysql--with-pgsql--with-oracle
2 选择支持 MySQL 后, 在 MySQL 编译安装的情况下时, 也需要在编译参数中指定 MySQL 的 lib。
3 编译时,dictionary.h 和 super-smack.cc 报错:
...... dictionary.h:93: error: ‘strlen’ was not declared in this scope super-smack.cc:126: error: ‘strlen’ was not declared in this scope
在 super smack 源代码的 src
目录,找到 dictionary.h, super-smack.cc,分别加上#include <string.h>
。
4 编译时,query.cc 报错
query.cc:200: error: cast from ‘char*’ to ‘unsigned int’ loses precision query.cc:200: error: cast from ‘char*’ to ‘unsigned int’ loses precision query.cc:219: error: cast from ‘char*’ to ‘unsigned int’ loses precision query.cc:219: error: cast from ‘char*’ to ‘unsigned int’ loses precision
在 super smack 源代码的 src
目录, 找到 query.cc文件,将上面指定的 200, 219 行中的unsigned int
改为unsigned long
。
用其测试 MySQL 之前奏
1 看 Makefile 才知道, smack 文件是放在 /usr/share/smacks
这个目录下(开始并不知道源代码中有一份), 产生的数据文件是在/var/smack-data
目录下
1
2
3
4
|
...
SMACKS_DIR =
/usr/share/smacks
DATADIR =
/var/smack-data
...
|
2 根据 MySQL 的参数对应修改 /usr/share/smacks 目录下的 select-key.smack 和 update-select.smack 文件。包括 user, host, db, pass, 还有,最重要的 socket 路径。
3 未将 super smack 的 bin 目录加入 PATH 时,则还需:
1
2
3
4
5
|
gen_data_file
"gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d"
;
#改为
gen_data_file
"./gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d"
;
#或者直接
gen_data_file
"/usr/local/super-smack/bin/gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d"
;
|
4 因为在 select-key.smack 和 update-select.smack 文件中指定的数据文件是 words.dat, 而安装默认情况下 words.dat 为空文件:
1
2
3
4
5
6
|
[root@localhost smack-data]
# ls -al
total 5320
drwxr-xr-x 2 root root 4096 May 26 18:12 .
drwxr-xr-x 24 root root 4096 May 26 17:25 ..
-rw-r--r-- 1 root root 5421337 May 26 17:25 .. http_auth.dat
-rw-r--r-- 1 root root 0 May 26 17:25 .. words.dat
|
所以,需将 select-key.smack 和 update-select.smack 文件中指定的数据 words.dat 改为 http_auth.dat(其实为了统一,最好也是 http_auth.dat,因为文件中指定测试的表名是 http_atuh)。
当然,为了不修改,也可以在开始先执行如下命令:
1
|
[root@localhost bin]
# /usr/local/super-smack/bin/gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d > /var/smack-data/words.dat
|
5 将 /usr/share/smacks 下文件 copy 到 /usr/local/super-smack/bin/ 目录下:
1
|
[root@localhost super-smack]
# cp /usr/share/smacks/* bin/
|
运行
1
2
3
4
5
|
[root@localhost bin]
# ./super-smack -d mysql select-key.smack 20 1000
Query Barrel Report
for
client smacker1
connect: max=2204ms min=1ms avg= 221ms from 20 clients
Query_type num_queries max_time min_time q_per_s
select_index 40000 0 0 5017.26
|
参数:
-d
指定测试的数据库管理系统的类型。20
20 个线程1000
每个线程 1000 个查询
实际上,还有-D
参数来指定数据文件,默认路径如前面提到是 /var/smack-data
, 这个路径需跟 select-key.smack 和 update-select.smack 指定的一致。
返回结果:
- max=2204ms min=1ms avg= 221ms from 20 clients 连接的最大、最小及平均花费时间。
- q_per_s|5017.26 QPS,每秒请求处理数
- 40000, 脚本中,对查询次数做了翻倍处理, 所以, 20 × 1000 x 2 = 40,000.