公開日:12/25/2021  更新日:3/26/2022

  • twitter
  • facebook
  • line

JMeter でOutOfMemory が発生した際の対処法

エラー内容

巨大ファイルをダウンロードする性能テストを実施した際にOOM (Out Of Memory) が発生。

java.lang.OutOfMemoryError: Java ヒープ・スペース
	at org.apache.commons.io.output.AbstractByteArrayOutputStream.toByteArrayImpl(AbstractByteArrayOutputStream.java:366) ~[commons-io-2.8.0.jar:2.8.0]
	at org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:163) ~[commons-io-2.8.0.jar:2.8.0]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.toByteArray(HTTPSamplerBase.java:1997) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.readResponse(HTTPSamplerBase.java:1974) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.readResponse(HTTPAbstractImpl.java:476) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:673) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1296) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1285) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) ~[ApacheJMeter_core.jar:5.4.1]
	at java.lang.Thread.run(Thread.java:866) [?:?]

解決方法

bin/jmeter.bat に記載のJAVAオプションを変更してheapサイズを変更。
最大ヒープ・サイズを 1G から16G に変更した。

修正前

set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m

修正後

set HEAP=-Xms1g -Xmx16g -XX:MaxMetaspaceSize=256m

※ 性能テストでは CUIモードでJmeterを起動する
テストシナリオを保存したjmxファイルのパス、JMeterのログの出力先、web report の出力先を引数に設定してコマンド実行。

jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]

戻る