1. 介绍

Gatling是一款基于Scala 开发的高性能服务器性能测试工具,它主要用于对服务器进行负载等测试,并分析和测量服务器的各种性能指标。目前仅支持http协议,可以用来测试web应用程序和RESTful服务。

除此之外它拥有以下特点:

  • 支持Akka Actors 和 Async IO,从而能达到很高的性能
  • 支持实时生成Html动态轻量报表,从而使报表更易阅读和进行数据分析
  • 支持DSL脚本,从而使测试脚本更易开发与维护
  • 支持录制并生成测试脚本,从而可以方便的生成测试脚本
  • 支持导入HAR(Http Archive)并生成测试脚本
  • 支持Maven,Eclipse,IntelliJ等,以便于开发
  • 支持Jenkins,以便于进行持续集成
  • 支持插件,从而可以扩展其功能,比如可以扩展对其他协议的支持
  • 开源免费

2. 使用

下载解压即可使用:http://gatling.io/#/download
解压后目录结构:

1
2
3
4
5
6
7
├── bin
├── conf
├── gatling-tests
├── lib
├── results
├── target
└── user-files

3. 文件目录介绍

  • bin目录下有2个脚本,gatling和recorder, gatling用来运行测试, recorder用来启动录制脚本的UI的(不推荐使用)。
  • conf目录是关于Gatling自身的一些配置。
  • lib目录是Gatling自身依赖的库文件。
  • results目录用来存放测试报告的。
  • user-files目录是用来存放测试脚本的。
  • target: 你启动运行组件后,gatling会为你编译好所有的.scala脚本,而编译后的class文件就会在这里;

当运行gating脚本的时候,其会扫描user-files目录下的所有文件,列出其中所有的Simulation(一个测试类,里面可以包含任意多个测试场景)。选择其中一个Simulation,然后填写Simulation ID和运行描述,这个都是为报告描述服务的。

4. Demo 运行

在Gatling的下载包里默认包含了一个demo示例,
在项目目录下执行shell命令:

1
/work/gatling-2.3.1 $ ./bin/gatling.sh

Gatling 会遍历user-files,列出所有的Simulation

1
2
3
4
5
6
7
8
GATLING_HOME is set to /work/gatling-2.3.1
Choose a simulation number:
[0] computerdatabase.BasicSimulation
[1] computerdatabase.advanced.AdvancedSimulationStep01
[2] computerdatabase.advanced.AdvancedSimulationStep02
[3] computerdatabase.advanced.AdvancedSimulationStep03
[4] computerdatabase.advanced.AdvancedSimulationStep04
[5] computerdatabase.advanced.AdvancedSimulationStep05

这里我们在终端中输入 0,代表选择computerdatabase.BasicSimulation执行,
之后输入两次 回车,就可以开始执行了,执行完成会在results目录下生成网页报告。

1
2
Reports generated in 0s.
Please open the following file: /work/gatling-2.3.1/results/basicsimulation-1535978730687/index.html

欢迎扫码关注公众号,更好的交流

欢迎扫码关注公众号,更好的交流