垃圾回收机制
https://yemengying.com/2016/05/13/jvm-GC/
http://www.cnblogs.com/jing99/p/6072059.html
CMS组合
-Xms3g -Xmx3g -XX:NewRatio=2 -XX:SurvivorRatio=6 -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=2 -XX:+UseCompressedClassPointers -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=1024m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=1M -Xloggc:/var/app/log/front-server/gc.log -XX:+PrintTLAB -XX:+PrintCodeCache -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=85
G1组合
-Xms1024m -Xmx1024m -XX:SurvivorRatio=8 -XX:-UseCompressedClassPointers -XX:MetaspaceSize=150m -XX:MaxMetaspaceSize=1024m -XX:+UseG1GC -XX:+PrintGCDetails -Xloggc:/var/log/gc.log -XX:+PrintGCTimeStamps
UseParallelOldGC组合
-Xms1024m -Xmx1024m -XX:NewRatio=2 -XX:SurvivorRatio=8 -XX:+UseParallelOldGC -XX:-UseAdaptiveSizePolicy -XX:-UseCompressedClassPointers -XX:MetaspaceSize=150m -XX:MaxMetaspaceSize=1024m
参数说明
- -Xms:最小堆内存空间
- -Xmx:最大堆内存空间,最好和Xms一致,避免分配内存空间浪费系统资源
- -XX:SurvivorRatio:单个幸存区和伊甸区(Eden)的比例 S0:Eden=1:8
- -XX:+UseParNewGC:新生代的多线程收集器
- -XX:+UseConcMarkSweepGC:老年代的短暂停顿并发收集器
- -XX:-UseCompressedClassPointers:指针压缩
- -XX:MaxMetaspaceSize:最大元素据空间,默认为无限大,最好设置,避免无限大进程被OS KILL
GC组合
jmap转储dump文件
jmap -dump:file=DumpFileName.txt,format=b pid
jhat分析dump文件
jhat -J-Xmx1024m dump-file
OOM生成dump文件
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/heap/dump
查看JVM进程参数
jcmd pid VM.flags
jinfo -flags pid