当前位置:网站首页>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 ;
边栏推荐
- Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
- Hidden corners of coder Edition: five things that developers hate most
- Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
- kaili不能输入中文怎么办???
- [HCIA continuous update] overview of WLAN workflow
- Talk about seven ways to realize asynchronous programming
- To sort out messy header files, I use include what you use
- 利用win10计划任务程序定时自动运行jar包
- 超标量处理器设计 姚永斌 第6章 指令解码 摘录
- OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
猜你喜欢
Electronic pet dog - what is the internal structure?
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
【Hot100】32. 最长有效括号
To sort out messy header files, I use include what you use
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
什么是低代码开发?
The Block:USDD增长势头强劲
Difference between redis' memory obsolescence strategy and expiration deletion strategy
超大规模数仓集群在大型商业银行的落地实践
随机推荐
Hidden corners of coder Edition: five things that developers hate most
Summary of tx.origin security issues
Recast of recastnavigation
码农版隐秘的角落:作为开发者最讨厌的5件
Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
长城证券安全不 证券开户
整理混乱的头文件,我用include what you use
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
CocosCreator事件派发使用
电子宠物小狗-内部结构是什么?
[HCIA continuous update] WLAN overview and basic concepts
VSCode修改缩进不成功,一保存就缩进四个空格
如何进行MDM的产品测试
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
R language plot visualization: plot visualization of multiple variable violin plot in R with plot
【华为HCIA持续更新】SDN与FVC
Difference between redis' memory obsolescence strategy and expiration deletion strategy
With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
MVC mode and three-tier architecture