空手道网关:如何解决Java堆空间OutOfMemoyError? [英] karate-gatling: how to resolve java heap space OutOfMemoryError?

查看:25
本文介绍了空手道网关:如何解决Java堆空间OutOfMemoyError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试使用gatling-plugin与10个用户并行运行我们的功能测试(大约300个请求)

mvn clean test-compile gatling:test -Dkarate.env=test

在项目文件夹中使用以下.mvn/jvm.config本地maven选项:

-d64 -Xmx4g -Xms1g -XshowSettings:vm -Djava.awt.headless=true

在并行处理某些大响应时,网关进程被中止:

[ERROR] Failed to execute goal io.gatling:gatling-maven-plugin:3.0.2:test (default-cli) on project np.rest-testing: Gatling failed.: Process exited with an error: -1 (Exit value: -1) -> [Help 1]

使用以下堆栈跟踪:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid25960.hprof ...
Heap dump file created [1611661680 bytes in 18.184 secs]
Uncaught error from thread [GatlingSystem-scheduler-1]: Java heap space, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[GatlingSystem]
java.lang.OutOfMemoryError: Java heap space
        at akka.actor.LightArrayRevolverScheduler$$anon$3.nextTick(LightArrayRevolverScheduler.scala:269)
        at akka.actor.LightArrayRevolverScheduler$$anon$3.run(LightArrayRevolverScheduler.scala:235)
        at java.lang.Thread.run(Thread.java:748)

我尝试通过不同的方式将堆空间增加到10 GB(-Xmx10g):

  1. 通过环境属性MAVEN_OPTS=-Xmx10g
  2. 通过本地项目Maven选项.mvn/jvm.config
  3. 通过maven-surefire-plugin建议的配置here

尽管如您在maven进程开始时看到的那样,为maven进程分配了10 GB:

VM settings:
    Min. Heap Size: 1.00G
    Max. Heap Size: 10.00G
    Ergonomics Machine Class: client
    Using VM: Java HotSpot(TM) 64-Bit Server VM

但在每个gatling-plugin执行过程中仍会引发OutOfMemoryError

在分析每个堆转储时eclipse memory analyzer始终指示相同的结果:

84 instances of "com.intuit.karate.core.StepResult", loaded by "sun.misc.Launcher$AppClassLoader @ 0xc0000000" occupy 954 286 864 (90,44 %) bytes. 

Biggest instances:
•com.intuit.karate.core.StepResult @ 0xfb93ced8 - 87 239 976 (8,27 %) bytes... 

可以做些什么来减少堆空间使用并防止OutOfMemoryError? 谁能分享一些想法和经验?

推荐答案

经过一些调查后,我终于注意到,堆转储始终显示为1 GB。这意味着增加的堆空间未被gatling-plugin使用。

通过向插件添加以下JVM参数,即使在4 GB的情况下也可以解决问题:

<jvmArgs>
    <jvmArg>-Xmx4g</jvmArg>
</jvmArgs>

因此,通过以下gatling-plugin配置,错误不会再出现:

         <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>${gatling.plugin.version}</version>
            <configuration>
                <simulationsFolder>src/test/java</simulationsFolder>
                <includes>
                    <include>performance.test.workflow.WorkflowSimulation</include>
                </includes>
                <compilerJvmArgs>
                    <compilerJvmArg>-Xmx512m</compilerJvmArg>
                </compilerJvmArgs>
                <jvmArgs>
                    <jvmArg>-Xmx4g</jvmArg>
                </jvmArgs>
            </configuration>
        </plugin>

这篇关于空手道网关:如何解决Java堆空间OutOfMemoyError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆