项目性能优化—使用 JMeter 压测 SpringBoot 项目
我们的压力测试架构图如下:

配置 JMeter
在 JMeter 的 bin 目录,双击 jmeter.bat

新建一个测试计划,并右键添加线程组:

进行配置

一共会发生 4 万次请求。
ctrl + s 保存;
添加 http 请求:

配置 http 请求:

配置断言,来判断当前请求是否成功:

正常响应如下:


添加断言持续时间


添加察看结果树:

添加汇总报告:

相似的操作,也添加聚合报告:

相似的操作,添加图形结果:

相似的操作,添加汇总图:

发送请求测试
发送请求

压力测试结果解析
聚合报告

样本(Sample):发送请求的总样本数量
响应时间(RT):平均值,P90,P95,P99,Min,Max
异常(Error):出现错误的百分比
吞吐量(Throughput):被测试接口的吞吐能力
发送与接收数据量:KB/sec
察看结果树

记录了样本中每一次的请求
汇总报告
类似于聚合报告。
线程组配置解析
线程数:用来发送 http 请求的线程数量
线程组常用来模拟一组用户访问系统资源(接口)。如果接口响应速度快,就没必要使用太多线程数,如果响应慢,需要使用很多的线程,来测试接口能扛住的压力。如果客户机没有足够能力模拟较重负载,可以使用 JMeter 分布式压力测试。
Ramp-up(in-seconds):建立全部线程耗时:
代表隔多长时间执行,默认值是 0,0 代表同时并发,用于告知 JMeter 要在多长时间内建立全部线程。
循环次数:循环执行多少次操作
循环次数直接决定整个测试单个线程的执行时间,和整体测试执行时间。
单线程执行时间 = 单请求平均响应时间 * 循环次数
整个测试耗时= 单线程执行时间 + (Ramp-Up - Ramp-UP / 线程数)
JMeter 压测插件
Basic Graphs 主要显示:
Average Response Time 平均响应时间
Active Threads 活动线程数
Successful/Failed Transactions 成功/失败事务数
Additional Graphs 主要显示
Response Codes
Bytes ThroughputConnect Times
Latency
Hits/s
开启插件下载
下载地址: https://jmeter-plugins.org/install/Install/,官网上下载plugins-manager.jar直接在线下载,然后执行在线下载即可。

下载好后放到lib\ext
下;
再把 JMeter 重启;
可以看到插件管理器:

下载如下两个插件:

安装成功后添加如下三个监听器:
响应时间:jp@gc - Response Times Over Time
活动线程数:jp@gc - Active Threads Over Time
每秒事务数:jp@gc - Transactions per Second

性能关键指标分析
TPS:每秒的事务数
数字愈大,代表性能越好;
QPS:每秒的查询数量
数字愈大,代表性能越好(1TPS >= 1QPS)
吞吐量:每秒的请求数量
数字愈大,代表性能越好
文章转载自:随机的未知
评论