【问题标题】:karate-gatling: how to resolve java heap space OutOfMemoryError?karate-gatling:如何解决 Java 堆空间 OutOfMemoryError?
【发布时间】:2020-04-11 00:22:06
【问题描述】:

目前我正在尝试使用 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 进程分配了 10GB,但正如您在 maven 进程开始时看到的那样:

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? 有人可以分享一些想法和经验吗?

【问题讨论】:

    标签: karate gatling-plugin


    【解决方案1】:

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

    通过在插件中添加以下 jvm 参数,即使 4GB 也解决了问题:

    <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>
    

    【讨论】:

      【解决方案2】:

      你可以试试这个

      <configuration>
       <meminitial>1024m</meminitial>
       <maxmem>4096m</maxmem>
      </configuration>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-18
        • 1970-01-01
        • 2011-11-05
        • 2013-08-08
        • 1970-01-01
        相关资源
        最近更新 更多