Jmeter做性能压测时,会出现
java.lang.OutOfMemoryError: Java heap space
这样的异常,查看官网 http://jmeter.apache.org/usermanual/get-started.html
有以下办法:
Linux系统
1、在Jmeter的bin目录下新建文件 setenv.sh
# This is the file bin/setenv.sh,
# it will be sourced in by bin/jmeter
# Use a bigger heap, but a smaller metaspace, than the default
export HEAP="-Xms1G -Xmx1G -XMaxMetaspaceSize=192m"
# Try to guess the locale from the OS. The space as value is on purpose!
export JMETER_LANGUAGE=" "
修改HEAP的参数,官网对这个参数的描述
Java runtime options for memory management used when JMeter is started. Defaults to -Xms1g -Xmx1g -X:MaxMetaspaceSize=256m,
不知为何有的linux不识别MaxMetaspaceSize,可删除这个参数,调大后的参数
export HEAP="-Xms2G -Xmx12G"
2、在命令行执行前加上实际可用的内存,例如
JVM_ARGS="-Xms1024m -Xmx10240m"
完整命令如下
JVM_ARGS="-Xms10240m -Xmx10240m" /home/user/apache-jmeter-4.0/bin/jmeter -n -t /home/user/jmeter/jmeter_script/rsa.jmx -l /home/user/jmeter/jmeterlog/runLog.jtl -j /home/user/jmeter/jmeterlog/runLog.log