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 of jzawodn_ 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  15 select_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

解析super-smack的smack文件相关推荐

  1. 基于流式输入输出 使用Java借助GSON库 实现对大型asc文件的读入解析 并输出为JSON文件

    基于流式输入输出 使用Java借助GSON库 实现对大型asc文件的读入解析 并输出为JSON文件 致谢 1 为什么要使用流式输入输出(使用情景) 2 目标.主要思路及相关方法 2.1 目标 2.2 ...

  2. 文件同步是什么?解析6个最佳的文件同步应用软件

    文件同步应用程序是一项服务或程序,它提供了一种便捷的方式来在多台计算机或移动设备上自动文件同步.在登录文件同步应用程序的任何地方,都可以使用相同的文件来打开,编辑,复制,流式传输等,就像在最初上传文件 ...

  3. html书签解析,解析netscape样式书签html文件嵌套数组

    我想构建一个服务,可以解析netscape样式的书签html导出文件,并返回一个多维数组,其中的文件夹和书签嵌套,因为他们在哪里在文件中.解析netscape样式书签html文件嵌套数组 我发现了一些 ...

  4. custom-lib-path、engine-create的作用及如何使用他们parse-bbox(dete)deepstream-test1解析yolov5的engine引擎文件需要解析网络库(精)

    为什么yolov5不能被deepstream-test1直接调用?deepstream-test1如何解析yolov5的engine引擎文件 A.问题:为什么yolov5不能被deepstream-t ...

  5. Python解析CANoe录制的blf文件asc文件通用方法

    Python解析CANoe录制的blf文件&asc文件通用方法 一.背景     由于很多时候我们在录制日志文件的时候更愿意选择BLF文件,至少目前我见到的很多公司都是使用的BLF文件来作为最 ...

  6. Python解析CANoe录制的asc文件

    Python解析CANoe录制的asc文件 一.背景     由于很多时候我们需要单纯分析一些报文数据,筛选或者一些故障报文,这个时候,用CANoe打开太占用设备了,而且只能过滤到某一帧报文,当我们能 ...

  7. 用Python解析WinMerge生成的Patch文件

    这个代码是本人第一次用Python写的包含Class的代码. 该解析之前用VBA写过,刚刚学习了五天的Python, 检验一下自己学习的成果,也算给五一长假画上一个分号. 写的比较烂,自己看着都难受. ...

  8. 解析flash格式的swf文件

    解析flash格式的swf文件 问题:项目中遇到需要从展示全景的swf文件中提取缩略图,使用ffmpeg等视频转换文件不能解析这个swf文件 从网上找到一个可以解析swf并能获取图片的方法,原文链接: ...

  9. java 解析xml xmlns_dom4j解析带有xmlns的xml文件

    dom4j解析带有xmlns的xml文件 上一篇 / 下一篇  2013-01-22 10:03:23 / 个人分类:Java学习 使用dom4j来解析带有命名空间的xml文件, 由于dom4j的xp ...

  10. Java解析魔兽争霸3录像W3G文件(五):Action和APM计算

    在游戏进行中,玩家会进行各种操作,例如编队.移动.技能.造建筑等,这些操作就是Action.APM(Actions Per Minute),表示每分钟的操作次数,APM可以很好的反映玩家的手速和实力, ...

最新文章

  1. 网站优化关键词如何分类看好这四种!
  2. DevExpress的分隔条控件SplitterControl的使用
  3. android Word 显示文档结构图
  4. flutter打包的app有多大_Flutter原生混合开发
  5. 让我们Core在一起:ASP.NET Core amp; .NET Core
  6. mysql-视图、事物等
  7. 获取系统分辨率_一文弄懂高分辨率高速快门CMOS成像传感器技术应用现状
  8. Mac 配置selenium连接chrome
  9. C++ char/byte 转16进制字符串
  10. LinkedHashMap如何保证有序
  11. nvme分区选mbr还是guid_小白也会装系统 固态硬盘Win10热门主板Bios设置教程NVME和SATA...
  12. 9011,9012,9013,9014,8050,8550三极管的区别
  13. 基于HPC场景的集群管理系统(slurm系统初相识)
  14. 谈谈人们常说的“一时糊涂,鬼迷心窍”!
  15. 第一行代码-第二版(郭霖著)笔记(初识Android)
  16. adb 判断imei_获取设备序列号 SN码(对应:设置-关于手机-状态-序列号 )
  17. 变量命名神器 CODELF
  18. 浅析相机相关坐标系的相互转换(世界坐标系、相机坐标系、图像坐标系、像素坐标系、内参矩阵、外参矩阵、扭转因子)【相机标定计算机视觉】
  19. 爬虫问题小记 --- UnicodeEncodeError: 'gbk' codec can't encode character '\xa9' in position 25703: illegal
  20. ElementUI日期组件(DatePicker )图标定制

热门文章

  1. vsftpd 的配置项目
  2. webpack开发Vue配置
  3. SLES修改本地FTP安装源
  4. 模板-1-模板类的特化
  5. gitlab4安装mysql出问题解决方法
  6. poj 3125 Printer Queue(STL注意事项)
  7. EqualLogic全攻略视频[(四)高级管理]
  8. delphi tclientsocket接收不到返回数据_RS—485中教你主站发送报文结构、从站返回报文结构?系列11...
  9. python 多个列表_Python同时迭代多个列表
  10. Oracle Unicode转中文(解码)