当前位置:网站首页>Performance test of Gatling
Performance test of Gatling
2022-07-04 17:45:00 【Wu_ Candy】
One 、 Create project
Use mvn Create a project template
1、“cd Go to the folder where you want to create this project ”
2、 Input :mvn archetype:generate # After loading
3、 Input :gatling # select gatling Of mvn Prototype template
4、 Input :1 # Because only one is selected , So the input 1 that will do
5、 Input : 20 # The serial number of the version to be installed ",20 by gatling2.3.1
6、 Input :com.klicen # groupid Group name , It's usually XX.XX first XX Is the domain com、cn、org etc. , the second XX Name of the company
7、 Input :klicen # artifactId coordinate ID, Generally, it is the project name , A folder with the same name will be created in the current directory
8、 Input :1.0 # version Version name
9、 Input : klicen # package Package name
10、 Input :Y # confirm
Two 、IntelliJ IDEA Import the project
1、 Import the project -- Click on file-open- Select the project template we just created to import
2、 install scala plug-in unit , It can be used directly zip Install locally
3、 In the project src/test/scala Create scala class
The following example :
package cnblogsCase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class baidu extends Simulation{
// First step : Define a protocol to be used
val httpProtocol = http.baseUrl("https://www.baidu.com")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
// The second step : Define the steps to operate 1, Open Baidu home page
val homepage=repeat(5){ // Five times again
exec(http("home page").get("/").check(status.is(200))).pause(10 seconds)
}
// The third step : Define the steps to operate 2, Search on Baidu homepage AI keyword
val searchcb=repeat(5){// Five times again
exec(http("search cnblogs").get("/s").queryParam("wd","AI").check(status.is(200))).pause(10 seconds)
}
// Step four : Define the scene mode
val scn=scenario("search baidu home page").exec(homepage,searchcb)
// Step five : Load scenario execution
setUp(scn.inject(atOnceUsers(5)).protocols(httpProtocol))
}
4、 Copy this package Folder to E:\All\gatling\gatling-exe\user-files\simulations
5、 stay E:\All\gatling\gatling-exe\bin perform gatling.bat file
E:\All\gatling\gatling-exe\bin>gatling.bat
GATLING_HOME is set to "E:\All\gatling\gatling-exe"
JAVA = ""D:\Program Files\Java\jdk1.8.0_131\\bin\java.exe""
Choose a simulation number:
[0] cnblogsCase.baidu
[1] computerdatabase.BasicSimulation
[2] computerdatabase.advanced.AdvancedSimulationStep01
[3] computerdatabase.advanced.AdvancedSimulationStep02
[4] computerdatabase.advanced.AdvancedSimulationStep03
[5] computerdatabase.advanced.AdvancedSimulationStep04
[6] computerdatabase.advanced.AdvancedSimulationStep05
6、 Choose... From the list 0 【[0] cnblogsCase.baidu, The script we wrote 】
7、 You can see the report : as follows :
Simulation cnblogsCase.baidu completed in 104 seconds
Parsing log file(s)...
Parsing log file(s) done
Generating reports...
Global Information
> request count 36 (OK=36 KO=0 )
> min response time 18 (OK=18 KO=- )
> max response time 1106 (OK=1106 KO=- )
> mean response time 518 (OK=518 KO=- )
> std deviation 288 (OK=288 KO=- )
> response time 50th percentile 573 (OK=573 KO=- )
> response time 75th percentile 671 (OK=671 KO=- )
> response time 95th percentile 991 (OK=991 KO=- )
> response time 99th percentile 1100 (OK=1100 KO=- )
> mean requests/sec 0.346 (OK=0.346 KO=- )
Response Time Distribution
> t < 800 ms 31 ( 86%)
> 800 ms < t < 1200 ms 5 ( 14%)
> t > 1200 ms 0 ( 0%)
> failed 0 ( 0%)
or
Gatling The values of variables of have at least the following sources :
1、using Feeders—— file 、 database
2、extracting data from responses and saving them, e.g. with HTTP Check’s saveAs—— Extract and save content from the requested return value
3、manually with the Session API—— Use all kinds of java Provided function generation , The disadvantage is that it may affect the performance a little
3、 ... and 、 Virtual user scenario
for example :setUp( scn.inject( nothingFor(4 seconds)).protocols(httpConf))
1、nothingFor(duration): Set a stop time ;
Don't explain
2、atOnceUsers(nbUsers): Inject a certain number of virtual users immediately ;
setUp(scn.inject(atOnceUsers(50)).protocols(httpConf))
3、rampUsers(nbUsers) over(duration): Within the specified time , Set a certain number of virtual users to be injected step by step ;
setUp(scn.inject(rampUsers(50) over(30 seconds)).protocols(httpConf))
4、constantUsersPerSec(rate) during(duration): Define a constant number of concurrent users per second , Continue for a specified time ;
setUp(scn.inject(constantUsersPerSec(30) during(15 seconds)).protocols(httpConf))
5、constantUsersPerSec(rate) during(duration) randomized: Define a concurrency that increases or decreases randomly around a specified number of concurrencies per second , Last for a specified time ;
setUp(scn.inject(constantUsersPerSec(30) during(15 seconds) randomized).protocols(httpConf))
6、rampUsersPerSec(rate1) to (rate2) during(duration): Define a concurrent number interval , Run the specified time , The period of concurrent growth is a regular value ;
setUp(scn.inject(rampUsersPerSec(30) to (50) during(15 seconds)).protocols(httpConf))
7、rampUsersPerSec(rate1) to(rate2) during(duration) randomized: Define a concurrent number interval , Run the specified time , The period of concurrent growth is a random value ;
setUp(scn.inject(rampUsersPerSec(30)to(50)during(15seconds) randomized).protocols(httpConf))
8、heavisideUsers(nbUsers) over(duration): Define a continuous concurrency , The amount of growth around the smooth approximation of the haverside function , Last for a specified time ( The translator explains the haverside function ,H(x) When x>0 When to return to 1,x<0 When to return to 0,x=0 When to return to 0.5. Operating time , The concurrency number is a curve in the shape of a smooth parabola );
setUp(scn.inject(heavisideUsers(50) over(15 seconds)).protocols(httpConf))
9、splitUsers(nbUsers) into(injectionStep) separatedBy(duration): Define a cycle , perform injectionStep The injection inside , take nbUsers Requests are evenly distributed ;
setUp(scn.inject(splitUsers(50) into(rampUsers(10) over(10 seconds)) separatedBy(10 seconds)).protocols(httpConf))
10、splitUsers(nbUsers) into(injectionStep1) separatedBy(injectionStep2): Use injectionStep2 As a cycle , Separate injectionStep1 The injection of , Until the number of users reaches nbUsers;
setUp(scn.inject(splitUsers(100) into(rampUsers(10) over(10 seconds)) separatedBy atOnceUsers(30)).protocols(httpConf))
Request limits ( The original for Throttling)
If you want to set the number of requests per second , Instead of concurrency per second , Then you should consider using constantUsersPerSec(…) Set the arrival ratio of users . In most cases , Requests do not need to use request restrictions , Or at least redundant .
But in some cases , We need to use Gatling Self contained throttle Method , To limit the number of requests .
Be careful
- We still need to inject virtual users into the scene level . Request limits are only used to set a certain throughput in a given scenario , And the number and duration of users injected . This is to set a bottleneck , It's just It's a ceiling . If you do not set enough users , Will not reach this limit . If the injection duration does not reach the setting of the request limit , Then all virtual users are finished after ,simulation Will be terminated . If the injection time exceeds the request limit , Then request restrictions will work , prevent simulation Implementation .
- Request limits can be configured in each scenario , Move here to find more :http://gatling.io/docs/2.1.7/general/scenario.html#scenario-throttling
setUp(scn.inject(constantUsersPerSec(100) during(30 minutes))).throttle(
reachRps(100) in (10 seconds),
holdFor(1 minute),
jumpToRps(50),
holdFor(2 hours)
)
Explain the above code :
simulation Will limit every second 100 A request , continued 10 Second , Then maintain this throughput and continue 1 minute ; Then jump to every second 50 A request , Maintain this throughput 2 Hours ;
The request restrictions set in this code block are as follows :
- reachRps(target) in (duration): Set a constant throughput , And for a while ;
- jumpToRps(target): Immediately switch the limit to another throughput ;
- holdFor(duration): Maintain the current throughput for a certain time ;
边栏推荐
- [Huawei HCIA continuous update] SDN and FVC
- 使用3DMAX制作一枚手雷
- 如何进行MDM的产品测试
- Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
- DataKit——真正的统一可观测性 Agent
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- Load test practice of pingcode performance test
- 完美融入 Win11 风格,微软全新 OneDrive 客户端抢先看
- The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online
- 超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
猜你喜欢

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

创业两年,一家小VC的自我反思

上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索

Implementation of super large-scale warehouse clusters in large commercial banks

公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!

解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替

DataKit——真正的统一可观测性 Agent

一加10 Pro和iPhone 13怎么选?

Rainfall warning broadcast automatic data platform bwii broadcast warning monitor
![[HCIA continuous update] overview of WLAN workflow](/img/0a/b3986307589a9f7379fe1dd707b9f8.png)
[HCIA continuous update] overview of WLAN workflow
随机推荐
Image retrieval
斑马识别成狗,AI犯错的原因被斯坦福找到了丨开源
国产数据库TiDB初体验:简单易用,快速上手
开发者,MySQL专栏完更,助你轻松从安装到入门进阶
动态规划股票问题对比
【HCIA持续更新】WLAN概述与基本概念
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
什么是低代码开发?
Is BigDecimal safe to calculate the amount? Look at these five pits~~
R language plot visualization: plot visualizes overlapping histograms and uses geom at the top edge of the histogram_ The rug function adds marginal rug plots
La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.
数学分析_笔记_第7章:多元函数的微分学
创业两年,一家小VC的自我反思
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
就在今天丨汇丰4位专家齐聚,共讨银行核心系统改造、迁移、重构难题
正则表达式
Display opencv drawn pictures on MFC picture control control
Talk about seven ways to realize asynchronous programming
Ble HCI flow control mechanism