You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

jmeter-maven-plugin执行JMeter测试计划后出现Java HEAP内存问题

JMeter Maven插件堆内存溢出问题解决方案

问题描述

JMeter测试看起来运行正常结束。
但受堆内存问题影响,14:48:37 [info] Completed Test: FssBenchmark.jmx之后的输出内容缺失,正常情况下后续应输出如下内容:

[INFO] Test Results:
[INFO]  
[INFO] Tests Run: 1, Failures: 0

我已将堆内存调整为2048,仍存在HEAP问题。
实际运行日志如下:

[INFO] summary +      3 in 00:00:05 =    0.6/s Avg:  1651 Min:     1 Max:  2810 Err:     0 (0.00%) Active: 0 Started: 53 Finished: 53
[INFO] summary =    100 in 00:03:15 =    0.5/s Avg:  3664 Min:     1 Max: 47594 Err:     0 (0.00%)
[INFO] Tidying up ...    @ Wed Sep 15 18:33:06 UTC 2021 (1631730786136)
[INFO] ... end of run
[INFO] Completed Test: FssBenchmark.jmx
[INFO]  
[INFO] Executing test: FssStreamTest.jmx
[INFO] Writing log file to: /integration-tests/target/jmeter/logs/FssStreamTest.jmx.log
[INFO] WARNING: An illegal reflective access operation has occurred
[INFO] WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/integration-tests/target/jmeter/lib/xstream-1.4.9.jar) to field java.util.TreeMap.comparator
[INFO] WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
[INFO] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
[INFO] WARNING: All illegal access operations will be denied in a future release
[INFO] Creating summariser <summary>
[INFO] Created the tree successfully using /integration-tests/target/jmeter/testFiles/FssStreamTest.jmx
[INFO] Starting the test @ Wed Sep 15 18:33:07 UTC 2021 (1631730787166)
[INFO] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
[INFO] summary +     13 in 00:00:24 =    0.6/s Avg:  1721 Min:   534 Max:  3115 Err:     0 (0.00%) Active: 1 Started: 2 Finished: 1
[INFO] summary +     10 in 00:00:13 =    0.8/s Avg:  1273 Min:   535 Max:  2804 Err:     0 (0.00%) Active: 0 Started: 4 Finished: 4
[INFO] summary =     23 in 00:00:36 =    0.6/s Avg:  1526 Min:   534 Max:  3115 Err:     0 (0.00%)
[INFO] Tidying up ...    @ Wed Sep 15 18:33:43 UTC 2021 (1631730823796)
[INFO] ... end of run
[INFO] Completed Test: FssStreamTest.jmx
[INFO] 
[INFO] --- jmeter-maven-plugin:2.1.0:results (default-cli) @ integration-tests ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:37 min
[INFO] Finished at: 2021-09-15T18:33:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Java heap space -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
[INFO] Shutdown detected, destroying JMeter process...
[INFO] Shutdown detected, destroying JMeter process...

根因分析

你之前调整的2G堆内存是JMeter运行测试进程的内存,本次报错触发在jmeter-maven-plugin执行结果聚合阶段,属于Maven主进程的堆内存溢出,两个进程的内存配置相互独立,所以调整JMeter堆内存不会生效。

修复方案

  • 优先调整Maven进程堆内存,执行测试前先配置MAVEN_OPTS环境变量:
    • Linux/macOS终端:export MAVEN_OPTS="-Xmx4g -Xms2g"
    • Windows cmd:set MAVEN_OPTS=-Xmx4g -Xms2g
    • Windows PowerShell:$env:MAVEN_OPTS="-Xmx4g -Xms2g"
  • 可选优化项:
    • 测试运行时关闭JMeter内不必要的监听器(如查看结果树、图形化汇总等),仅保留结果文件输出,降低内存占用
    • 升级jmeter-maven-plugin到3.x以上版本,老版本2.1.0的结果聚合逻辑内存占用较高,新版本已做优化
    • 大数量级测试场景下,开启JMeter结果文件分批写入配置,避免全量测试结果加载到内存中

内容的提问来源于stack exchange,提问作者Sashin Sahasra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 20:54:03