JMeter 在 CentOS 的内存设置与调优
一 设置方式与推荐值
: "${HEAP:="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m"} 的行,调整为所需值,例如:: "${HEAP:="-Xms4g -Xmx4g -XX:MaxMetaspaceSize=512m"}"。建议将 -Xms 与 -Xmx 设为相同,避免运行期扩容抖动;-XX:MaxMetaspaceSize 用于控制元空间上限(JMeter 5.x 使用 Metaspace 而非 PermGen)。修改后需重启 JMeter 生效。export JVM_ARGS="-Xms4g -Xmx4g" 再执行 jmeter ...;或在命令前直接追加参数:jmeter -Xms4g -Xmx4g -n -t test.jmx ...。命令行参数优先级高于脚本中的 HEAP 默认值,适合临时调大或不同场景快速切换。二 生效验证与监控
jmeter -n -t your.jmx -l result.jtl,在启动日志中可见 JVM 参数回显,确认 -Xms/-Xmx 已生效。ps -ef | grep jmeter 或 jcmd <pid> VM.flags(需 JDK),可查看实际生效的 JVM 标志。三 常见报错与处理
java.lang.OutOfMemoryError: Java heap space(堆不足)There is insufficient memory for the Java Runtime Environment(JVM 内存分配失败)四 与系统相关的配套调优
ulimit -n 102400* soft nofile 65536
* hard nofile 65536
root soft nofile 65536
root hard nofile 65536
* soft nproc 65565
* hard nproc 65565
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.ip_local_port_range = 1024 65000
sysctl -p 使配置生效。五 分布式压测注意