1. Overview
1.概述
In the previous tutorial, we’ve seen how to use Gatling to load test a custom web application.
在前一个教程中,我们已经看到了如何使用Gatling来加载测试一个自定义的Web应用程序。
In this article we’ll make use the Gatling stress tool to measure the performance of the staging environment of this website.
在这篇文章中,我们将使用Gatling压力工具来测量这个网站的暂存环境的性能。
2. The Test Scenario
2.测试场景
Let’s first set up our main usage scenario – one that comes close to a typical user that might be browsing the site:
让我们首先设定我们的主要使用场景–一个接近于可能正在浏览网站的典型用户的场景。
- Go to the Home Page
- Open an Article from Home Page
- Go to Guides/REST
- Go to the REST Category
- Go to the Full Archive
- Open an Article from the Archive
3. Record the Scenario
3.记录情景
Now, we’ll record our scenario using the Gatling recorder – as follows:
现在,我们将使用加特林记录器来记录我们的场景–如下所示。
$GATLING_HOME/bin/recorder.sh
And for Windows users:
而对于Windows用户来说。
%GATLING_HOME%\bin\recorder.bat
Note: GATLING_HOME is your Gatling installation directory.
注意:GATLING_HOME是你的Gatling安装目录。
There are two modes for Gatling Recorder: HTTP Proxy and HAR Converter.
Gatling Recorder有两种模式:HTTP Proxy和HAR Converter。
We discussed the HTTP Proxy mode in detail in the previous tutorial – so let’s now have a look at the HAR Converter option.
我们在前篇教程中详细讨论了HTTP代理模式–所以现在让我们看看HAR转换器选项。
3.1. HAR Converter
3.1.HAR转换器
HAR is short for HTTP Archive – which is a format that basically records the full information about a browsing session.
HAR是HTTP档案的简称–这是一种格式,基本上记录了关于浏览会话的全部信息。
We can obtain HAR files from the browser then use the Gatling Recorder to convert it into a Simulation.
我们可以从浏览器中获得HAR文件,然后使用Gatling Recorder将其转换为Simulation。
We’ll create our HAR file with the help of the Chrome Developer Tools:
我们将在Chrome开发工具的帮助下创建我们的HAR文件。
- Menu -> More Tools -> Developer Tools
- Go to Network Tab
- Make sure Preserve log is checked
- After you finish navigating the website, right click on the requests you want to export
- Then, select Copy All as HAR
- Paste them in a file, then import it from the Gatling recorder
After you finish adjusting Gatling recorder to your preference, Click start.
在你完成调整加特林录音机到你的偏好后,点击开始。
Note that the output folder is by default GATLING_HOME/user-files-simulations
注意,输出文件夹默认为GATLING_HOME/user-files-simulations。
4. The Simulation
4.模拟
The generated simulation file is similarly written in Scala. It’s generally OK, but not super readable, so we’ll do some adjustments to clean up. Here is our final Simulation:
生成的模拟文件同样是用Scala写的。总的来说还可以,但不是超级可读,所以我们要做一些调整来清理。下面是我们最终的模拟文件。
class RestSimulation extends Simulation {
val httpProtocol = http.baseURL("http://staging.baeldung.com")
val scn = scenario("RestSimulation")
.exec(http("home").get("/"))
.pause(23)
.exec(http("article_1").get("/spring-rest-api-metrics"))
.pause(39)
.exec(http("rest_series").get("/rest-with-spring-series"))
.pause(60)
.exec(http("rest_category").get("/category/rest/"))
.pause(26)
.exec(http("archive").get("/full_archive"))
.pause(70)
.exec(http("article_2").get("/spring-data-rest-intro"))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
An important note here is that the full simulation file is much larger; here, we didn’t include static resources for simplicity.
这里需要注意的是,完整的模拟文件要大得多;在这里,我们没有包括静态资源,以示简单。
5. Run the Load Test
5.运行负载测试
Now, we can run our simulation – as follows:
现在,我们可以运行我们的模拟–如下所示。
$GATLING_HOME/bin/gatling.sh
And for Windows users:
而对于Windows用户来说。
%GATLING_HOME%\bin\gatling.bat
The Gatling tool will scan GATLING_HOME/user-files-simulations and list all found simulations for us to choose.
Gatling工具将扫描GATLING_HOME/user-files-simulations并列出所有找到的模拟,供我们选择。
After running the simulation here’s what the results look like:
运行模拟后,这里是结果的样子。
For one user:
对于一个用户来说。
> request count 304 (OK=304 KO=0)
> min response time 75 (OK=75 KO=-)
> max response time 13745 (OK=13745 KO=-)
> mean response time 1102 (OK=1102 KO=-)
> std deviation 1728 (OK=1728 KO=-)
> response time 50th percentile 660 (OK=660 KO=-)
> response time 75th percentile 1006 (OK=1006 KO=-)
> mean requests/sec 0.53 (OK=0.53 KO=-)
---- Response Time Distribution ------------------------------------
> t < 800 ms 183 ( 60%)
> 800 ms < t < 1200 ms 54 ( 18%)
> t > 1200 ms 67 ( 22%)
> failed 0 ( 0%)
For 5 simultaneous users:
对于5个同时使用的用户。
> request count 1520 (OK=1520 KO=0)
> min response time 70 (OK=70 KO=-)
> max response time 30289 (OK=30289 KO=-)
> mean response time 1248 (OK=1248 KO=-)
> std deviation 2079 (OK=2079 KO=-)
> response time 50th percentile 504 (OK=504 KO=-)
> response time 75th percentile 1440 (OK=1440 KO=-)
> mean requests/sec 2.411 (OK=2.411 KO=-)
---- Response Time Distribution ------------------------------------
> t < 800 ms 943 ( 62%)
> 800 ms < t < 1200 ms 138 ( 9%)
> t > 1200 ms 439 ( 29%)
> failed 0 ( 0%)
For 10 simultaneous users:
对于10个同时使用的用户。
> request count 3058 (OK=3018 KO=40)
> min response time 0 (OK=69 KO=0)
> max response time 44916 (OK=44916 KO=30094)
> mean response time 2193 (OK=2063 KO=11996)
> std deviation 4185 (OK=3953 KO=7888)
> response time 50th percentile 506 (OK=494 KO=13670)
> response time 75th percentile 2035 (OK=1976 KO=15835)
> mean requests/sec 3.208 (OK=3.166 KO=0.042)
---- Response Time Distribution ----------------------------------------
> t < 800 ms 1752 ( 57%)
> 800 ms < t < 1200 ms 220 ( 7%)
> t > 1200 ms 1046 ( 34%)
> failed 40 ( 1%)
Note that some of the requests failed when tested 10 simultaneous users – simply because the staging environment isn’t capable of handling that kind of load.
请注意,在测试10个同时使用的用户时,一些请求失败了–仅仅是因为暂存环境没有能力处理这样的负载。
6. Conclusion
6.结论
In this quick article we explored the HAR option of recording test scenarios in Gatling as well as did a simple initial test of baeldung.com.
在这篇快速文章中,我们探讨了在Gatling中记录测试场景的HAR选项,以及对baeldung.com做了一个简单的初始测试。