Gatling - install & start

基于Scala 开发的开源免费性能压测工具。主要用于测量基于HTTP的服务器,比如Web应用程序,RESTful服务等。
方方面面的原因,准备用Gatling做性能测试,对这个工具做一个简单的研究。

Install

去官网下载: http://gatling.io/download/
下载之后,解压到相应的目录中去。

  • bin 目录下有2个脚本,gatling和recorder, gatling用来运行测试, recorder用来启动录制脚本的UI的。
  • conf 目录是关于Gatling自身的一些配置。
  • lib 目录是Gatling自身依赖的库文件。
  • results 目录用来存放测试报告的。
  • target
  • user-files
    • bodies
    • data 数据目录,csv参数文件存放在这里
    • simulations 测试脚本(所有的脚本都在这里)

Recorder

运行bin目录下的’recorder.bat’,打开Recorder Window。

录制之前要先设置浏览器用Gatling Recorder’s proxy,录制之后,保存脚本。录制一个搜索:

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
package default

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL("https://www.baidu.com")
.inferHtmlResources()
.acceptHeader("image/png,image/*;q=0.8,*/*;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
.userAgentHeader("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0")

val headers_0 = Map("Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

val uri1 = "https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_65682a2.js"
val uri2 = "www.baidu.com"
val uri3 = "http://baidu.com"

val scn = scenario("RecordedSimulation")
.exec(http("request_0")
.get(uri3 + "/")
.headers(headers_0)
.resources(http("request_1")
.get("/img/baidu_jgylogo3.gif"),
http("request_2")
.get("/img/bd_logo1.png")))
.pause(4)
.exec(http("request_3")
.get("/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&ch=&tn=baidu&bar=&wd=gatling&rn=&oq=&rsv_pq=e632af2400018ab7&rsv_t=21efo2auHiH8VwtAPnYwISgfAskcOJ5NLsAxSJh2B%2BZEb6LFvXLa%2BPVXxwc&rqlang=cn")
.headers(headers_0)
.resources(http("request_4")
.get("/aladdin/tpl/dict3/repeat_small.c6d62112.png"),
http("request_5")
.get("/aladdin/img/dic3/iconall.gif")))

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

录制功能应该一般都不太会用到。

Run

运行bin目录下的’gatling.bat’

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
GATLING_HOME is set to "D:\gatling-charts-highcharts-bundle-2.2.5"
JAVA = ""C:\Program Files\Java\jdk1.8.0_77\bin\java.exe""
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
[6] default.RecordedSimulation
6
Select simulation id (default is 'recordedsimulation'). Accepted characters are a-z, A-Z, 0-9, - and _
searching
Select run description (optional)

Simulation default.RecordedSimulation started...

================================================================================
2017-05-09 15:45:00 5s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=6 KO=0 )
> request_0 (OK=1 KO=0 )
> request_0 Redirect 1 (OK=1 KO=0 )
> favicon.ico Redirect 1 (OK=1 KO=0 )
> baidu_jgylogo3.gif Redirect 1 (OK=1 KO=0 )
> request_1 Redirect 1 (OK=1 KO=0 )
> baidu.svg Redirect 1 (OK=1 KO=0 )

---- RecordedSimulation --------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done:0
================================================================================



================================================================================
2017-05-09 15:45:07 11s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=16 KO=0 )
> request_0 (OK=1 KO=0 )
> request_0 Redirect 1 (OK=1 KO=0 )
> favicon.ico Redirect 1 (OK=1 KO=0 )
> baidu_jgylogo3.gif Redirect 1 (OK=1 KO=0 )
> request_1 Redirect 1 (OK=1 KO=0 )
> baidu.svg Redirect 1 (OK=1 KO=0 )
> request_2 Redirect 1 (OK=1 KO=0 )
> bd_logo1.png Redirect 1 (OK=1 KO=0 )
> jquery-1.10.2.min_65682a2.js Redirect 1 (OK=1 KO=0 )
> request_3 (OK=1 KO=0 )
> request_4 (OK=1 KO=0 )
> baidu_jgylogo3.gif (OK=1 KO=0 )
> request_5 (OK=1 KO=0 )
> favicon.ico (OK=1 KO=0 )
> bd_logo1.png (OK=1 KO=0 )
> baidu.svg (OK=1 KO=0 )

---- RecordedSimulation --------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done:0
================================================================================



================================================================================
2017-05-09 15:45:07 11s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=19 KO=0 )
> request_0 (OK=1 KO=0 )
> request_0 Redirect 1 (OK=1 KO=0 )
> favicon.ico Redirect 1 (OK=1 KO=0 )
> baidu_jgylogo3.gif Redirect 1 (OK=1 KO=0 )
> request_1 Redirect 1 (OK=1 KO=0 )
> baidu.svg Redirect 1 (OK=1 KO=0 )
> request_2 Redirect 1 (OK=1 KO=0 )
> bd_logo1.png Redirect 1 (OK=1 KO=0 )
> jquery-1.10.2.min_65682a2.js Redirect 1 (OK=1 KO=0 )
> request_3 (OK=1 KO=0 )
> request_4 (OK=1 KO=0 )
> baidu_jgylogo3.gif (OK=1 KO=0 )
> request_5 (OK=1 KO=0 )
> favicon.ico (OK=1 KO=0 )
> bd_logo1.png (OK=1 KO=0 )
> baidu.svg (OK=1 KO=0 )
> u=4004482432,3155140380&fm=85&s=BDB6E7161778482054FC7... (OK=1 KO=0 )
> u=3971883911,3367482058&fm=85&s=B1B6E5365F2F7B094AFC0... (OK=1 KO=0 )
> u=3374980953,196157295&fm=85&s=0940C30203BDB2690CD90E... (OK=1 KO=0 )

---- RecordedSimulation --------------------------------------------------------
[##########################################################################]100%
waiting: 0 / active: 0 / done:1
================================================================================


Simulation default.RecordedSimulation completed in 9 seconds
Parsing log file(s)...
Parsing log file(s) done
Generating reports...

================================================================================
---- Global Information --------------------------------------------------------
> request count 19 (OK=19 KO=0 )
> min response time 52 (OK=52 KO=- )
> max response time 1570 (OK=1570 KO=- )
> mean response time 337 (OK=337 KO=- )
> std deviation 367 (OK=367 KO=- )
> response time 50th percentile 223 (OK=223 KO=- )
> response time 75th percentile 380 (OK=380 KO=- )
> response time 95th percentile 893 (OK=893 KO=- )
> response time 99th percentile 1435 (OK=1435 KO=- )
> mean requests/sec 2.111 (OK=2.111 KO=- )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms 17 ( 89%)
> 800 ms < t < 1200 ms 1 ( 5%)
> t > 1200 ms 1 ( 5%)
> failed 0 ( 0%)
================================================================================


Reports generated in 0s.
Please open the following file: D:\gatling-charts-highcharts-bundle-2.2.5\results\searching-1494315895552\index.html

Report


唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!