当前位置:网站首页>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 ;
边栏推荐
- What if Kaili can't input Chinese???
- 整理混乱的头文件,我用include what you use
- wuzhicms代码审计
- Recast of recastnavigation
- Detectron2 installation method
- Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt
- DataKit——真正的统一可观测性 Agent
- 关于nacos启动时防火墙开启8848的坑
- How to choose one plus 10 pro and iPhone 13?
- [Huawei HCIA continuous update] SDN and FVC
猜你喜欢
Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
The Block:USDD增长势头强劲
CocosCreator事件派發使用
Firewall basic transparent mode deployment and dual machine hot standby
[Huawei HCIA continuous update] SDN and FVC
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索
NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析
The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online
随机推荐
雨量预警广播自动化数据平台BWII 型广播预警监测仪
Is it safe for Bank of China Securities to open an account online?
使用3DMAX制作一枚手雷
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
7 RSA Cryptosystem
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
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.
整理混乱的头文件,我用include what you use
What are cache penetration, cache breakdown, and cache avalanche
将Opencv绘制图片显示在MFC Picture Control控件上
Ble HCI flow control mechanism
curl 命令妙用
ble HCI 流控机制
【HCIA持续更新】WLAN工作流程概述
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
DataKit——真正的统一可观测性 Agent
CocosCreator事件派发使用
上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
Recast of recastnavigation