前言
在vdbench 执行过程中,偶尔会遇到OOM的场景,这个问题大部分原因是因为Java堆内存不足导致。本文将介绍该问题的解决方法。
问题确认
通过排查stdout.html日志 和 实际vdbench所在host的环境信息,确认问题是因为Java 堆内存不足导致。
检查 stdout.html 日志
在stdout.html 日志中,一般会出现“Out of memory”字样,日志示例如下:
19:06:53.114 19:06:53.113 Message to master: anchor=/mnt/1752145565207843955/GMptt: Created 4,900 of 10,000 files (49.00%)
19:08:40.116 19:08:38.022 Out of memory:
19:08:40.116
19:08:40.116 modify the vdbench script and increase the '-Xmx512m' value where 512m equals the java heap size requested.
19:08:40.116 19:08:40.115 If the error message says 'unable to create new native thread' modify the vdbench script adding '-Xss256k' or lower value for the java thread stack size.
19:08:40.116
19:08:40.116
19:08:40.116 19:08:40.116 Examples are for Solaris. For other platforms see the Java provider's documentation
19:08:40.119 19:08:40.116 Java Heap in MB. max: 1820.500; current: 1820.500; used: 1585.150; free: 235.350
19:08:40.126 java.lang.OutOfMemoryError: GC overhead limit exceeded
确认Java 堆大小
在Linux 环境执行下面命令,关注输出 中 InitialHeapSize 和 MaxHeapSize。
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
intx CompilerThreadStackSize = 0 {pd product}
uintx ErgoHeapSizeLimit = 0 {product}
uintx HeapSizePerGCThread = 87241520 {product}
uintx InitialHeapSize := `536870912` {product}
uintx LargePageHeapSizeThreshold = 134217728 {product}
uintx MaxHeapSize := `2147483648` {product}
intx ThreadStackSize = 1024 {pd product}
intx VMThreadStackSize = 1024 {pd product}
如上面输出所示,InitialHeapSize 和 MaxHeapSize 分别为 512M和2G。
解决问题
临时解决方案
直接执行命令 export _JAVA_OPTIONS="-Xms1G -Xmx8G"(重启后失效)
永久解决方案
将命令export _JAVA_OPTIONS="-Xms1G -Xmx8G追加到 /etc/profile、 ~/.zshrc、 ~/.bashrc 配置文件最后(根据不同发行版而定),再执行 source 操作即可。
校验
设置完成之后,echo $_JAVA_OPTIONS 会显示最新设置的值。