解析super-smack的smack文件

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/294713.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JSP是不是Java发展史上的一大败笔?

JSP一个年代传奇人物,它的诞生成果了网络的三国鼎立的局势,可是,几年的结构的风烟席卷,让JSP逐渐淡出这个前史舞台,有人不由宣布这样的感叹,JSP是不是Java开展史上的一大败笔呢? 查询样本 让咱们…

Android之使用PopupWindow使用和总结

不废话,先爆照 说明: 那个灰色背景是不能滑动里ListView里面的内容的 第一步:我们需要背景view 下面是我的background.xml文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/t…

Cell发文!施一公科研团队取得重大突破

全世界只有3.14 % 的人关注了爆炸吧知识本文来源&#xff1a;科学网&#xff08;有删减&#xff09;北京时间2020年12月29日凌晨0时&#xff0c;《细胞》&#xff08;Cell&#xff09;发表中科院院士、西湖大学校长施一公课题组的一项新研究。研究首次报道了γ-分泌酶&#xff…

MAUI 跨平台播客应用程序(Conf 2021)

介绍在.NET Conf 2021大会上&#xff0c;微软展示了基于.NET6 跨平台应用程序, 具有ASP.NET Core、Blazor、.NET MAUI、微服务等功能。浏览由 ASP.NET Core 和 Blazor 提供支持的 .NET Podcasts 应用的实时运行版本&#xff1a;https://dotnetpodcasts.azurewebsites.net/项目体…

mysql enum_MySQL数据库中关于ENUM类型的详细解释

MySQL数据库中&#xff0c;因为工作的需求&#xff0c;我们可能会用到ENUM类型&#xff0c;但是由于此类型不是很常用&#xff0c;我们可能对其也不是很了解。没关系&#xff0c;本文我们就对ENUM类型做一些详细的解释&#xff0c;希望能够对您有所帮助。ENUM类型是一个字符串对…

Linux系统新手学习的11点建议

随着Linux应用的扩展许多朋友开始接触Linux&#xff0c;根据学习Windwos的经验往往有一些茫然的感觉&#xff1a;不知从何处开始学起。这里介绍学习Linux的一些建议。 一、从基础开始&#xff1a;常常有些朋友在Linux论坛问一些问题&#xff0c;不过&#xff0c;其中大多数的问…

Android之如何实现通讯录的搜索并且让匹配到的数据变颜色

不废话,先爆照 第一步:实现搜索 已经实现了通讯录功能,但是需要搜索,可以支持中文名字搜索,写入电话号码搜索,还有名字拼音,以及名字第一个字的首字母来搜索,这里介绍名字搜索,然后数据是我们公司TCL(020)所有员工的信息,目前还没有写到后…

复习一下日志等级类型

linux操作系统的日志有多种信息等级类型&#xff0c;今天好好复习一下&#xff1a; 1、info&#xff1a;信息说明&#xff1b; 2、notice&#xff1a;较info更需注意的信息&#xff1b; 3、warning&#xff08;warn&#xff09;&#xff1a;和现实生活中的warning不同&#xff…

mysql映射超_Hibernate的映射类型 hibernate mysql映射类型

(转)http://blog.csdn.net/zxy_snow/article/details/7214222Hibernate的映射类型 hibernate mysql映射类型1、Hibernate的映射类型 hibernate mysql映射类型Hibernate 映射类型Java 类型标准 SQL 类型大小和取值范围integer 或者 intint 或者 java.lang.IntegerINTEGER4 字节l…

dotnet 将自动代码格式化机器人带入团队 GitLab 平台

给团队带入一个 代码格式化机器人 能提升团队的幸福度&#xff0c;让团队的成员安心写代码&#xff0c;不用关注代码格式化问题&#xff0c;将格式代码这个粗活交给机器人去做。同时也能减少在代码审查里撕格式化问题的时间&#xff0c;让更多的时间投入到更有价值的工作上本文…

Notion,我来,语雀,有道等几个云笔记

最近打算放弃wolai产品的使用&#xff0c;所以有必要总结一下这些年用过的那些笔记。从最早开始用Evernote&#xff0c;然后麦库&#xff0c;为知&#xff0c;然后有道&#xff0c;onenote&#xff0c;一直到Notion&#xff0c;我来&#xff0c;语雀等等&#xff0c;都有各自的…

玩转Javascript 给JS写测试

给js写测试已经不是什么稀奇的事情了&#xff0c;最近项目里用了jasmine和JsTestDriver两种js测试框架。JsTestDriver易于与持续构建系统相集成并能够在多个浏览器上运行测试轻松实现TDD风格的开发。当在项目中配置好JsTestDriver以后&#xff0c;如同junit测试java文件一般&am…

Android 之自定义view实现水波纹效果

在实际的开发中&#xff0c;很多时候还会遇到相对比较复杂的需求&#xff0c;比如产品妹纸或UI妹纸在哪看了个让人兴奋的效果&#xff0c;兴致高昂的来找你&#xff0c;看了之后目的很明确&#xff0c;当然就是希望你能给她&#xff1b; 在这样的关键时候&#xff0c;身子板就一…

FFLIb Demo CQRS

使用FFLIB 构建了一个demo&#xff0c;该demo模拟了一个常见的游戏后台架构&#xff0c;该demo主要有一下亮点&#xff1a; FFLIB 实现进程间通信非常方便基于CQRS 思想构建LogicServer使用Event Publish/Subscribe&#xff0c; 实现各个模块的解耦合基于Event 实现实体对象的单…

【自定义标签开发】01-标签简介和开发第一个标签

自定义标签简介自定义标签主要用于移除Jsp页面中的java代码。要使用自定义标签移除jsp页面中的java代码&#xff0c;只需要完成以下两个步骤:1.编写一个实现Tag接口的java类&#xff0c;把页面java代码移到这个java类中(标签处理器类)。2.编写标签库描述(tld)文件&#xff0c;在…

三联《少年》创刊,各领域佼佼者畅言新知,帮少年建立思维素养体系!

▲点击查看很多中国小孩的成长是断层的。10岁前被视作可爱稚子&#xff0c;被大人护着走&#xff1b;18岁猛然被定义为成年人&#xff0c;要选择大学、专业&#xff0c;开始面对感情。中间的人生呢&#xff1f;“你是个学生&#xff0c;学习是本职&#xff0c;现在谈什么人生&a…

mysql utf8 bin设置_[mysql]修改collation为utf8_bin

mysql默认字段值区分大小写&#xff1a;character-set-serverutf8collation-serverutf8_bininit-connectSET NAMES utf8;SELECT DEFAULT_CHARACTER_SET_NAME charset, DEFAULT_COLLATION_NAME collationFROM information_schema.SCHEMATA WHERE SCHEMA_NAME billing01;SELECT …

C# WPF MVVM开发框架Caliburn.Micro自定义引导程序④

01—自定义引导程序在上一部分中&#xff0c;我们讨论了Caliburn.Micro WPF应用程序的最基本配置&#xff0c;并演示了与操作和约定相关的两个简单功能。在这一部分中&#xff0c;我想进一步探讨Bootstrapper类。让我们首先将应用程序配置为使用IoC容器。本例中我们将使用内置容…

Android 使用XmlPullParser解析xml

这里我们假设要解析的xml文件名为&#xff1a;test.xml&#xff0c;我们将其放在assets路径中。 xml文件内容为&#xff1a; <?xml version1.0 encodingutf-8 standaloneyes ?> <books><book id"1"><name>Java编程思想</name><pr…

链表之打印两个有序链表的公共部分

题目:打印两个有序链表的公共部分 package com.chenyu.zuo.linkedList; /*** 打印有序链表的公共部分* @author 陈喻*题目:给定两个有序链表的头指针head1和head2,打印出两个链表的公共部分*思路:因为有序*如果head1的值小于head2,则head1往下移动*如果head2的值小于head1,…