什么是Gatling
Gatling是Scala编写、基于akka和netty的压测工具,主要针对http服务做测试,可做负载测试(load testing)并分析性能指标。
Performance testing类型
在开始学习使用Gatling之前,我们先弄清楚性能测试的几种类型
- load testing: 使用预定的用户数和流量测试吞吐量(throughput)
- stress testing: 不断增大负载,寻找断点(breakpoint)
soak testing:长时间使用稳定流量测试,发现性能瓶颈(bottleneck)
如何使用
预先安装jdk,安装idea(安装scala插件)
下载,链接
解压gatling安装包,并运行bin目录下的gatling.sh使用方式一:脚本启动
./gatling.sh GATLING_HOME is set to /opt/kit/gatling-charts-highcharts-bundle-3.7.6 Choose a simulation number: [0] computerdatabase.BasicSimulation [1] computerdatabase.advanced.AdvancedSimulationStep01 [2] computerdatabase.advanced.AdvancedSimulationStep02 [3] computerdatabase.advanced.AdvancedSimulationStep03 [4] computerdatabase.advanced.AdvancedSimulationStep04 [5] computerdatabase.advanced.AdvancedSimulationStep05 0 Select run description (optional) Simulation computerdatabase.BasicSimulation started... Reports generated in 0s. # 他的报告会产生在results目录下 Please open the following file: /opt/kit/gatling-charts-highcharts-bundle-3.7.6/results/basicsimulation-20220521061306544/index.html使用方式二:界面
./recorder.sh
后面如果需要使用更多recorder功能会重新开一篇,本篇不做更多赘述
scala编程测试
- 预先安装idea、scala插件和maven
- 创建新项目:mvn archetype:generate
- mvn gatling:test -Dgatling.simulationClass=simulations.LoadSimulationDesign
数据解读
关注的几个指标
- Transaction Response Times 交易响应时间
- Throughput 吞吐量
Errors 错误数
实例-不同类型的网关性能对比
参考
- 参考官方文档,官方文档
- B站教程
- 博客-gatling全教程