当前位置:网站首页>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 ;
边栏推荐
- Display opencv drawn pictures on MFC picture control control
- 斑马识别成狗,AI犯错的原因被斯坦福找到了丨开源
- Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
- Ks007 realizes personal blog system based on JSP
- Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
- gatling 之性能测试
- 电子宠物小狗-内部结构是什么?
- With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
- 【HCIA持续更新】网络管理与运维
- NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
猜你喜欢

Cocoscreator event dispatch use

超大规模数仓集群在大型商业银行的落地实践

创业两年,一家小VC的自我反思
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下

Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue

Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see

雨量预警广播自动化数据平台BWII 型广播预警监测仪

要上市的威马,依然给不了百度信心

7 RSA密码体制

Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
随机推荐
动态规划股票问题对比
网页游戏引擎
如何进行MDM的产品测试
regular expression
[template] [Luogu p4630] duathlon Triathlon (round square tree)
How to choose one plus 10 pro and iPhone 13?
Two methods of MD5 encryption
Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt
大规模服务异常日志检索
[test development] software testing - Basics
缓存穿透、缓存击穿、缓存雪崩分别是什么
【Hot100】32. 最长有效括号
Load test practice of pingcode performance test
通过事件绑定实现动画效果
补能的争议路线:快充会走向大一统吗?
Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
安信证券属于什么档次 开户安全吗
【Proteus仿真】基于VSM 串口printf调试输出示例
What is low code development?
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