JMeter Maven mojo 抛出带有大型 JTL 文件的 IllegalArgumentException

JMeter Maven mojo throws IllegalArgumentException with large JTL file

当我 运行 我的 JMeter 在我的线程组上进行大循环计数(15 个 HTTP 请求的 100 次迭代)测试时,我从 JMeter 中得到了一个巨大的 JTL 文件。

这是我使用的 jmeter-maven-plugin (https://github.com/jmeter-maven-plugin/jmeter-maven-plugin) 的一个问题,它使用 java.util.Scanner 扫描 JTL 文件寻找 "false" 以查看是否测试失败。因为文件太大 (1.8GB),所以出现以下故障。

[ERROR] Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.10.1:jmeter (jmeter-tests) on project performance-tests: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.10.1:jmeter failed. IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.10.1:jmeter (jmeter-tests) on project performance-tests: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.10.1:jmeter failed.
       at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
       at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
       at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
       at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
       at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
       at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
       at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
       at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
       at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
       at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:497)
       at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
       at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
       at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
       at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.10.1:jmeter failed.
       at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
       at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
       ... 20 more
Caused by: java.lang.IllegalArgumentException
       at java.nio.CharBuffer.allocate(CharBuffer.java:334)
       at java.util.Scanner.makeSpace(Scanner.java:840)
       at java.util.Scanner.readInput(Scanner.java:795)
       at java.util.Scanner.findWithinHorizon(Scanner.java:1685)
       at com.lazerycode.jmeter.FailureScanner.hasTestFailed(FailureScanner.java:36)
       at com.lazerycode.jmeter.JMeterMojo.parseTestResults(JMeterMojo.java:70)
       at com.lazerycode.jmeter.JMeterMojo.execute(JMeterMojo.java:54)
       at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
       ... 21 more

我正在使用 ignoreResultFailures = true 作为 jmeter-maven-plugin 的参数来解决这个问题,这避免了它使用 java.util.Scanner 和失败。理想情况下,jmeter-maven-plugin 可以处理非常大的 JTL 文件,但 JTL 文件的大小似乎有点极端。

是否有任何可以减小 JTL 文件大小的 JMeter 设置?

检查您的测试计划是否启用了 "Functional Test Mode"。

http://jmeter.apache.org/usermanual/listeners.html

The information to be saved is configurable. For maximum information, choose "xml" as the format and specify "Functional Test Mode" on the Test Plan element. If this box is not checked, the default saved data includes a time stamp (the number of milliseconds since midnight, January 1, 1970 UTC), the data type, the thread name, the label, the response time, message, and code, and a success indicator. If checked, all information, including the full response data will be logged.

如果选中,这将导致 JTL 文件很大,因为所有详细的请求和响应数据都会被保存。也许您打开它是为了调试您的测试而忘记将其关闭?

您似乎存储了太多,即导致大量开销的响应数据。所以建议:

  • 使用 CSV 输出格式
  • 不存储响应数据(至少对于成功的采样器)

所以在 user.properties 文件中添加接下来的两行(位于 JMeter 安装的 /bin 文件夹下)

jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.response_data=false

您需要重新启动 JMeter 才能使更改生效。

示例 "good" 结果保存配置应如下所示:

引用material: