当前位置:网站首页>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 ;
边栏推荐
- Master the use of auto analyze in data warehouse
- 【Hot100】32. 最长有效括号
- [system analyst's road] Chapter 7 double disk system design (structured development method)
- What are cache penetration, cache breakdown, and cache avalanche
- leetcode:421. The maximum XOR value of two numbers in the array
- 长城证券安全不 证券开户
- 码农版隐秘的角落:作为开发者最讨厌的5件
- 国产数据库TiDB初体验:简单易用,快速上手
- Datakit -- the real unified observability agent
- Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
猜你喜欢
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
kaili不能输入中文怎么办???
超标量处理器设计 姚永斌 第5章 指令集体系 摘录
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
MVC mode and three-tier architecture
7 RSA Cryptosystem
[Huawei HCIA continuous update] SDN and FVC
防火墙基础透明模式部署和双机热备
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
随机推荐
CocosCreator事件派發使用
简单易用的地图可视化
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
整理混乱的头文件,我用include what you use
Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
Kunming Third Ring Road Closure project will pass through these places. Is there one near your home?
What if Kaili can't input Chinese???
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
The Ministry of human resources and Social Security announced the new construction occupation
Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
Pytorch深度学习之环境搭建
S5PV210芯片I2C适配器驱动分析(i2c-s3c2410.c)
就在今天丨汇丰4位专家齐聚,共讨银行核心系统改造、迁移、重构难题
Superscalar processor design yaoyongbin Chapter 7 register rename excerpt
【HCIA持续更新】WLAN概述与基本概念
What is low code development?
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
RecastNavigation 之 Recast
[HCIA continuous update] WLAN overview and basic concepts