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]
[root@localhost
tmp]
[root@localhost
super-smack-1.3]
[root@localhost
super-smack-1.3]
[root@localhost
super-smack-1.3]
|
说明
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]
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)。
当然,为了不修改,也可以在开始先执行如下命令:
5 将 /usr/share/smacks 下文件 copy 到 /usr/local/super-smack/bin/ 目录下:
1
|
[root@localhost
super-smack]
|
运行
1
2
3
4
5
|
[root@localhost
bin]
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.26QPS,每秒请求处理数
-
40000, 脚本中,对查询次数做了翻倍处理, 所以, 20 × 1000 x 2 = 40,000.
Super-smack是一款强大的数据库压测工具,现在支持mysql和PostgreSQL两种数据库,你可以通过简单的配置文件(.smack)来生成一系列测试环境:测试数据,测试表;在测试的过程中,你可以控制客户端的并发数量以及执行频率,根据业务场景配置不同sql,以及他们的执行比率来满足我们需要的业务测试场景;
在安装完super-smack工具后,我们会在smack文件目录中看到一些文件: select-key.smack , update-select.smack这些都是工具自带的配置文件,在运行Super-smack工具来压测DB之前,需要准备压测的表,压测数据,应用场景的sql语句,连接数据库的配置等信息,这些都可以在smack文件中配置完成。
我们只需要依葫芦画瓢,修改其中的配置就行了;
$./super-smack -d mysql -D /home/mysql/xuancan/super-smack/super-data /home/mysql/xuancan/super-smack-1.3/smacks/my.smack 10 15
Query Barrel Report for client smacker
connect: max=3ms min=0ms avg= 0ms from 10 clients
Query_type num_queries max_time min_time q_per_s
select_akey 1000 16 2 497.42
select_by_id 10000 0 0 4974.16
select_userid_aid 5000 0 0 2487.08
update_by_id 1500 4 0 746.12
上面的my.smack配置文件中我配置了按照select_akey(按照akey查询),select_by_id (按照主键id查询),select_userid_aid(按照userid和aid查询),update_by_id(根据主键更新) 四种业务场景的sql,客户端有10个,每个客户端轮询执行15次的压测场景,其中我们比较关注的是qps,当然得到的测试数据还和主机服务器的配置有关,数据量相关,不能一概而论。
我们拷贝一份select-update.smack文件,并重命名为my.smack,开始编辑my.smack文件:
client “admin”
{
user “root”;
host “localhost”;
db “test”;
pass “”;
socket “/u01/mysql/run/mysql.sock”;
}
该选项是用于配置admin client,由于我们在本机上进行压测,所以使用root用户不用指定密码,如果你在远程客户端上进行压测,那么就需要指定pass密码了;socket用于指定连接mysql使用的sock文件,super-smack默认会到”/tmp/mysql.sock” or “/var/lib/mysql/mysql.sock”这两个地方去读smack文件,我们这里指定了/u01/mysql/run/mysql.sock;
table “auth”
{ client “admin”;
// if the table is not found or does not pass the checks, create it, with the following, dropping the old one if needed
create ” CREATE TABLE auth(
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`userid` bigint(20) unsigned NOT NULL COMMENT ‘用户id’,
`nick` varchar(32) NOT NULL COMMENT ‘nick’,
`aid` bigint(20) unsigned NOT NULL COMMENT ‘应用id’,
`akey` varchar(256) NOT NULL,
`skey` varchar(500) NOT NULL COMMENT ‘skey’,
PRIMARY KEY (`id`),
UNIQUE KEY `ind_auth_userid` (`userid`,`aid`) USING BTREE,
KEY `ind_auth_akey` (akey) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=gbk”;
min_rows “90000″; // the table must have at least that many rows
data_file “userid.dat”; // if the table is empty, load the data from
//this file
gen_data_file “gen-data -n 90000 -f %10-12s%n,%25-25s,%n,%d”;
// if the file above does not exist, generate it with the above command
}
该选项用于定义压测的表:首先这里引用了前面定义的admin client,该表将会按照admin client的定义在test库中检查,如果该表没有,那么将会创建该表,同时我们指定了该表的最小行数,如果表中的行数没有达到min_rows,那么super-smack将会删除掉该表,重建该表;如果该表为空,将会从userid.dat中load数据到该表中,如果改文件不存在,则将用gen_data产生该文件:
%n表示可以从1开始递增的数值,可用于表中的主键
%d表示随机的产生数值
%s表示随机生产一些字母
10-12表示产生字母的范围长度
//define a dictionary
dictionary “userid”
{
type “rand”; // userid are retrieved in random order
source_type “file”; // userid come from a file
source “user.dat”; // file location
delim “,”; // take the part of the line before ,
file_size_equiv “45000″; // if the file is greater than this
//divive the real file size by this value obtaining N and take every Nth
//line skipping others
}
该数据字典用于配置sql查询条件中的值,
type:rand表示随机的从userid.dat中抽取值;
seq表示值是连续的
unique表示用gen-date产生唯一的值
source_type:file表示数据来自于磁盘的文件
list表示由用户提供带有分割符的数据(”one”,”two”,”three”)
template表示当type为unique的时候使用,比如jzawodn_%07d” generates values composed ofjzawodn_and a seven-digit number.
Source:存放在/home/mysql/xuancan/super-smack/super-data中的文件userid.dat
Delim:表示如果你使用带有分隔符的文件,delim告诉super-smack什么分隔符分隔文件
File_size_equiv:如果你的数据字典文件非常大,该选项将会很有用,如果你的文件为10k,指定file_size_equiv为1024,那么super-smack将会使用1/10的数据来测试;
备注:如果我们的查询值有多个,比如根据aid+userid来查询,那么需要定义两个数据字典:aid和userid。
SELECT aid INTO OUTFILE “/home/mysql/xuancan/super-smack/super-data/aid.dat”
FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”‘
LINES TERMINATED BY “\n”
FROM auth;
SELECT useid INTO OUTFILE “/home/mysql/xuancan/super-smack/super-data/userid.dat”
FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”‘
LINES TERMINATED BY “\n”
FROM auth;
SELECT akey INTO OUTFILE “/home/mysql/xuancan/super-smack/super-data/akey.dat”
FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”‘
LINES TERMINATED BY “\n”
FROM auth;
//define a query
query “select_by_userid”
{
query “select * from auth where userid = ‘$userid’”;
// $word will be substitute with the read from the ‘userid’ dictionary
type “select_by_userid”;
// query stats will be grouped by type
has_result_set “y”;
// the query is expected to return a result set
parsed “y”;
// the query string should be first processed by super-smack to do
// dictionary substitution
}
query “update_by_aid”
{
query “update auth set akey=’$akey’ where aid= ‘$aid’”;
// $word will be substitute with the read from the ‘word’ dictionary
// note that the first word is not the same as the second, as each is
// a separate random draw from the dictionary
type “update_index”;
// query stats will be grouped by type
has_result_set “n”;
// the query is expected to return a result set
parsed “y”;
// the query string should be first processed by super-smack to do
// dictionary substitution
}
定义查询:query定义查询的sql,其中查询的值有刚才定义的数据字典word来获得
Type:在生成结果的时候显示的名字;
Has_result_set:如果是sql为select,则该值设置为y,若为update,则为n
Parsed:表示word的值数据字典是将该值置为y
// define database client type
client “smacker”
{
user “test”; // connect as this user
pass “test”; // use this password
host “localhost”; // connect to this host
db “test”; // switch to this database
socket “/u01/mysql/run/mysql.sock”; // this only alies to MySQL and is
// ignored for PostgreSQL
query_barrel “2 select_akey 15select_by_id 5 select_userid_aid 10 update_by_id“; // on each round
}
与前面定义的admin client不同的是在smacker client中多定义了query_barrel,query_barrel定义了查询的顺序和执行次数,也是就是我们常说的业务场景,你的select update delete的比例是多少;
main
{
smacker.init(); // initialize the clients
smacker.set_num_rounds($2); // second arg on the command line defines
// the number of rounds for each client
smacker.create_threads($1);
// first argument on the command line defines how many client instances
// to fork. Anything after this will be done once for each client until
// you collect the threads
smacker.connect();
// you must connect after you fork
smacker.unload_query_barrel(); // for each client fire the query barrel
// it will now do the number of rounds specified by set_num_rounds()
// on each round, query_barrel of the client is executed
smacker.collect_threads();
// the master thread waits for the children, each child reports the stats
// the stats are printed
smacker.disconnect();
// the children now disconnect and exit
}
最后定义的中我们需要注意$1和$2两个参数,也就是我们调用super-smack进行压测的时候的10 15,10代表了有多少客户端同时来进行测试,15则代表了每个客户端轮询执行多少次查询;
参考:http://imysql.cn/docs/High_Performance_MySQL/0596003064/hpmysql-CHP-3-SECT-3.html
相关推荐
1. 测试工具介绍:文档提到了mysqlslap、sysbench、supersmack等工具,这些都是用于测试MYSQL性能的工具。 - mysqlslap是一个用于模拟多用户访问MySQL数据库的性能测试工具,它可以用来进行并发读写测试。 - ...
为了达到这个目标,使用了四个测试工具:Mysqlslap、mysql benchmark suite、sysbench和supersmack。测试用例包括并发写能力、并发事务处理能力、单线程功能测试以及大数据量下的读写性能对比。 在并发写能力测试中...
- MySQL基准测试:如mysqlsla、sql-bench、Super Smack、Percona's TPCC-MYSQL Tool和sysbench。 - MySQL代理:SOHU-DBProxy、Altas、cobar和Oceanus用于优化MySQL性能和负载均衡。 - 备份工具:mysqldump、...
MySQL基准测试工具如mysqlsla、sql-bench、Super Smack等,MySQL Proxy如SOHU-DBProxy、Atlas、cobar和Oceanus。物理备份有Xtrabackup和LVM Snapshot,逻辑备份工具如mysqldump、mysqlhotcopy、mydumper等。 9. **...
- 压测与基准:mysqlsla、sql-bench、Super Smack、Percona's TPCC-MYSQL Tool、sysbench。 - 代理与备份:MySQL Proxy工具如SOHU-DBProxy、Altas、cobar、Oceanus,以及物理备份工具Xtrabackup、LVM Snapshot。 ...
16. 基准测试:多种MySQL基准测试工具如mysqlsla、sql-bench、Super Smack和Percona's TPCC-MYSQL Tool评估数据库性能。 17. 逻辑备份:mysqldump、mysqlhotcopy、mydumper、MySQLDumper和mk-parallel-dump/mk-...
15. **MySQL基准测试**: 使用mysqlsla、sql-bench、Super Smack、Percona's TPCC-MYSQL Tool和sysbench来衡量数据库性能。 16. **MySQL代理**: SOHU-DBProxy、Altas、cobar、Oceanus提供MySQL的负载均衡和故障切换...
Supersmack - **功能**:一款开源的MySQL性能测试工具,支持多种数据库类型,包括MySQL。它可以帮助用户进行大规模的压力测试。 - **特点**:具有高度可配置性和灵活性,支持多种类型的负载生成。 - **使用方法**...
mysql测试工具super_smack及mysqlslap的安装介绍、配置文档介绍,相关测试
super.onCreate(icicle); Log.i("XMPPClient", "onCreate called"); setContentView(R.layout.main); // 初始化界面元素 mRecipient = (EditText) this.findViewById(R.id.recipient); mSendText = ...
4. **Super-smack**:这是由MySQL AB的程序员编写的另一个开源工具,同样支持多线程并发压力测试,具有高度可定制性。 在安装和使用这些工具时,通常需要根据具体的操作系统和MySQL版本来调整。例如,在Red Hat 5.5...
除了Web服务器和数据库测试工具,还有一些专门针对特定场景的工具,如Database test suite用于数据库的全面测试,super-smack则专注于分布式系统的压力测试。 在实际使用中,根据测试需求,可以选择合适的工具组合...
4. **Super-smack**:由MySQL AB的程序员开发的另一款开源产品,同样支持多线程并发压力测试,具有高度的可定制性。 #### 三、测试工具的安装与配置 以**MySQLslap**为例,其安装通常随MySQL默认安装包一同提供,...
开发者需要学习如何使用XMPP库(如Smack或Strophe.js)来实现这些功能,并且可能需要对UI进行定制以达到微信的用户体验。 4. **语音通话实现**:即时通讯中的语音通话通常需要额外的技术支持,如ICE(Interactive ...