Gatling作为一款开源免费的性能测试工具越来越受到广大程序员的欢迎。免费当然是好的,最缺钱的就是程序员了;开源更好啊,缺啥功能、想做定制化的可以自己动手,丰衣足食。其实我最喜欢的原因是其提供了简洁强大的API,原生支持命令行运行,不像JMeter那样需要在界面上点来点去。另外其出色的扩展API和轻量级的HTML报表都值得让人称道。

Gatling版本

Gatling的的官方网站是http://gatling-tool.org/。目前Gatling有两个主线版本,一个是Gatling 1,最新版本是1.5.3;一个是Gatling 2,最新版本是2.0.0-M3a。Gatling 2使用了JDK7进行编译,使用的Scala版本是2.10,它对Gatling的API进行了一些重构和重新设计,内部也有一些调整。 目前Gatling 2还在开发阶段,所以如果要在项目中使用的话最好还是使用Gatling 1.5.3。

安装Gatling

其实Gatling是款绿色软件,可以直接从https://github.com/excilys/gatling/wiki/Downloads下载指定的版本。下载下来解压缩以后,我们可以看到其目录结构。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
twer@bowen-huang:~/sourcecode/GatlingWorkShop/gatling-charts-highcharts-1.5.2$ tree -L 2
.
├── bin //可执行文件目录
│ ├── gatling.bat
│ ├── gatling.sh
│ ├── recorder.bat
│ └── recorder.sh
├── conf //配置目录
│ ├── application.conf
│ ├── gatling.conf
│ └── logback.xml
├── lib //依赖的程序库
│ ├── akka-actor-2.0.4.jar
│ ├── async-http-client-1.7.18.20130621.jar
│ ├── commons-io-2.4.jar
│ ├── commons-lang-2.6.jar
│ ├── commons-math3-3.1.1.jar
│ ├── commons-pool-1.6.jar
│ ├── compiler-interface-0.12.3-sources.jar
│ ├── config-1.0.1.jar
│ ├── gatling-app-1.5.2.jar
│ ├── gatling-charts-1.5.2.jar
│ ├── gatling-charts-highcharts-1.5.2.jar
│ ├── gatling-core-1.5.2.jar
│ ├── gatling-http-1.5.2.jar
│ ├── gatling-jdbc-1.5.2.jar
│ ├── gatling-metrics-1.5.2.jar
│ ├── gatling-recorder-1.5.2.jar
│ ├── gatling-redis-1.5.2.jar
│ ├── grizzled-slf4j_2.9.2-0.6.10.jar
│ ├── incremental-compiler-0.12.3.jar
│ ├── jaxen-1.1.6.jar
│ ├── joda-convert-1.2.jar
│ ├── joda-time-2.2.jar
│ ├── jodd-core-3.4.4.jar
│ ├── jodd-lagarto-3.4.4.jar
│ ├── json-path-0.8.2.fix24.jar
│ ├── json-smart-1.1.1.jar
│ ├── jsoup-1.7.2.jar
│ ├── logback-classic-1.0.12.jar
│ ├── logback-core-1.0.12.jar
│ ├── netty-3.6.6.Final.jar
│ ├── opencsv-2.3.jar
│ ├── redisclient_2.9.2-2.10.jar
│ ├── scala-compiler-2.9.3.jar
│ ├── scala-library-2.9.3.jar
│ ├── scalate-core_2.9-1.6.1.jar
│ ├── scalate-util_2.9-1.6.1.jar
│ ├── scopt_2.9.2-2.1.0.jar
│ ├── slf4j-api-1.7.5.jar
│ ├── xercesImpl-2.11.0.jar
│ ├── xml-apis-1.4.01.jar
│ ├── xstream-1.4.3.jar
│ └── zinc-0.2.5.jar
├── results //性能测试结果存放目录
│ └── blogsimulation-20131218210445
├── target //性能测试脚本编译结果
│ ├── cache
│ ├── classes
│ └── zincCache
└── user-files //性能测试脚本源文件
├── data
├── request-bodies
└── simulations

Gatling在user-files目录中提供了几个性能测试脚本的示例。不过由于脚本中被测试的网站已经无法访问,所以我自己写了几个简单的测试脚本,已经放置到了Github上,可以通过https://github.com/huangbowen521/GatlingWorkShop下载。

1
2
3
4
5
6
7
twer@bowen-huang:~/sourcecode/GatlingWorkShop/gatling-charts-highcharts-1.5.2/user-files$ tree simulations
simulations
└── blog
├── blog.scala
└── github.scala 1 directory, 2 files

可以看到在simulations目录下有两个文件,一个是我给自己的博客写的性能测试脚本,一个是给github写的一个性能测试脚本。

运行Gatling

在命令行下运行bin目录下的Gatling.sh(如果是windows用户,请运行Gatling.bat)。Gatling会自动列出当前所有的测试脚本供自己选择,然后会让填写simulation id(模拟Id)以及run description(运行描述)。输入完毕后按回车键测试即可启动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
twer@bowen-huang:~/sourcecode/GatlingWorkShop/gatling-charts-highcharts-1.5.2$ ./bin/gatling.sh
GATLING_HOME is set to /Users/twer/sourcecode/GatlingWorkShop/gatling-charts-highcharts-1.5.2
Choose a simulation number:
[0] blog.BlogSimulation
[1] blog.GithubSimulation
1
Select simulation id (default is 'githubsimulation'). Accepted characters are a-z, A-Z, 0-9, - and _
github
Select run description (optional)
testing github Simulation blog.GithubSimulation started… ……
……
…… Simulation finished.
Simulation successful.
Generating reports...
Reports generated in 0s.
Please open the following file : /Users/twer/sourcecode/GatlingWorkShop/gatling-charts-highcharts-1.5.2/results/github-20131223214957/index.html

可以看到命令行中最后一行中标示了性能测试报表的存放路径。

查看测试报告

Gatling的测试报表其实就是一个html文件。Gatling使用了HighCharts这款JavaScript库来进行报表的展示。另外Gatling还提供了方便的接口用来自定义报告的展示。

以下是报表的部分截图。

测试脚本示例

这是GithubSimulation的性能测试脚本。其实它就是Scala的一个类,继承自Simulation。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package blog

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._ class GithubSimulation extends Simulation {
var httpConf = httpConfig.
baseURL("https://github.com") var scn = scenario("search in github.com")
.exec(
http("home page")
.get("/")
.check(status.is(200)))
.pause(0, 12)
.exec(
http("do search")
.get("/search")
.queryParam("q", "gatling")
.check(status.is(200))) setUp(scn.users(500).ramp(10).protocolConfig(httpConf))
}

在这个类中定义了一个httpConf,指定了被测网站的根目录。

1
2
     var httpConf = httpConfig.
baseURL("https://github.com")

然后定义了一个测试场景,用户先访问Github首页,检查http返回状态码是否为200,然后暂停一段时间后再执行一个查询操作,查询关键字是gatling,检查http返回状态码是否为200。

1
2
3
4
5
6
7
8
9
10
11
     var scn = scenario("search in github.com")
.exec(
http("home page")
.get("/")
.check(status.is(200)))
.pause(0, 12)
.exec(
http("do search")
.get("/search")
.queryParam("q", "gatling")
.check(status.is(200)))

最后指定500个用户模拟该测试场景。500个用户以每秒50个递增,持续10秒。

1
     setUp(scn.users(500).ramp(10).protocolConfig(httpConf))

技术栈

这里列出了Gatling的一些主要的技术栈。

  • Akka Actors. Gatling 使用了Akka作为其并发编程的运行时。Akka的Actors模式能够有效的绕过JVM上多线程带来的性能问题。

  • Scala.选择Scala最大的原因是因为Scala可以很好的集成Akka,另一原因是作为一款运行在JVM上的语言,Scala更容易提供给用户简洁强大的API设计。

  • Async Http Client. 使用这款开源库来是实现异步http通讯。并且使用了Netty调用http。

  • Highcharts及Highstock. Gatling使用Highcarts和Highstock这两款JavaScript库来进行测试结果报表的展示。


其实Gatling并不完美,比如目前支持的协议并不多,不支持对数据库的性能测试,不能进行分布式性能测试等。当然Gatling也在不断的进步,看好你哦!

Gatling->次时代性能测试利器的更多相关文章

  1. 如何利用gatling创建一个性能测试例

    [原创博文,转载请声明出处] 基于上一篇博文介绍如何源码编译创建自己的gatling可执行工具,今天介绍一下如何基于gatling做性能测试! 由于gatling的测试例脚本是基于scala写的,所以 ...

  2. 地图性能测试利器PerfQA Analyzer

    PerfQA Analyzer作为一个地图性能测试工具,能针对ArcGIS 技术堆栈的系统进行性能问题的排查,用于系统试运行阶段的压力测试以及在线系统运维.大大减轻了GIS系统管理员的性能调优工作压力 ...

  3. 实战一:LoadRunner性能测试利器

    转自:https://blog.csdn.net/weixin_42350428/article/details/82106603 企业的网络应用环境都必须支持大量用户,网络体系架构中含各类应用环境且 ...

  4. 学习Scala第一篇-从hello World开始

    最近开始系统性的学习scala.其实之前使用过scala的,比如我在用Gatling这款性能测试工具的时候就接触到了scala了.Gatling本身就是用Scala写的,而且Gatling的性能测试配 ...

  5. 使用jMeter测试Solr服务接口

    之前一直用ab做简单的服务接口测试,ab功能强悍,使用简单,但是没有生成专题图和表格等功能,因此,我们决定使用jmeter来作为我们测试工具.接下来,我们将详细介绍jmeter使用的步骤,主要包括:j ...

  6. 图书简介:Spring Batch批处理框架

    大数据时代批处理利器,国内首度原创解析Spring Batch框架. 内容简介: <Spring Batch 批处理框架>全面.系统地介绍了批处理框架Spring Batch,通过详尽的实 ...

  7. web性能测试的新利器 - Gatling 介绍

    转载:http://www.51testing.com/html/10/26810-852956.html 最近发现了一个新的性能测试工具Gatling,貌似比Jmeter还好玩.这几天就先简单介绍一 ...

  8. 新一代服务器性能测试工具Gatling

    新一代服务器性能测试工具Gatlinghttp://automationqa.com/forum.php?mod=viewthread&tid=2898&fromuid=2

  9. 性能测试工具之Gatling

    转载:http://ningandjiao.iteye.com/blog/2004579 Gatling一直是久闻其名但是未得机会运用,正好最近有需求做性能测试,于是趁此机会熟悉了一下,可以说,这是目 ...

随机推荐

  1. json 判断字段

    1方式一 !("key" in obj) 方式二 obj.hasOwnProperty("key")  //obj为json对象. 2获取不确定键的值 for( ...

  2. codeforce div 377

    #include <bits/stdc++.h> using namespace std; #define pb push_back #define lb lower_bound #def ...

  3. Linux 中write()函数的出错情况及处理

    write函数首先将进程需要发送的数据先放在进程缓冲区中,然后向socket的发送缓冲区进行拷贝,在此,可能出现这样情况,即当进程缓冲区中的数据量大于此时发送缓冲区中所能接受的数据量时,若此时处于阻塞 ...

  4. [原创]PCB知识补充

    近期又要使用Altium进行PCB板的绘制,算起来从大学课上第一次接触Protel99SE到现在已经算是半个熟练工了.不过现在想来还是能回忆起第一次使用的情景,对着一幅简单的原理图使用着自动连线的功能 ...

  5. JS事件冒泡

    JavaSciprt事件中有两个很重要的特性:事件冒泡以及目标元素. 事件冒泡: 当一个元素上的事件被触发的时候,比如说鼠标点击了一个按钮,同样的事件将会在那个元素的所有祖先元素中被触发.这 一过程被 ...

  6. 让spark运行在mesos上 -- 分布式计算系统spark学习(五)

    mesos集群部署参见上篇. 运行在mesos上面和 spark standalone模式的区别是: 1)stand alone 需要自己启动spark master 需要自己启动spark slav ...

  7. 拓扑排序 POJ 2367

    今天网易的笔试,妹的,算法题没能A掉,虽然按照思路写了出来,但是尼玛好歹给个测试用例的格式呀,吐槽一下网易的笔试出的太烂了. 就一道算法题,比较石子重量,个人以为解法应该是拓扑排序. 就去POJ找了道 ...

  8. iOS10适配及Xcode8配置

    一.证书管理 用Xcode8打开工程后,比较明显的就是下图了,这个是苹果的新特性,可以帮助我们自动管理证书.建议大家勾选这个Automatically manage signing(Ps.但是在bea ...

  9. makeinfo: command not found

    解决办法:sudo apt-get install texinfo

  10. anelife

    无论如何要把安e生活做到最棒! 1.先用脑再用力!