JVM启动参数优化模板

90 阅读2分钟

参考:JVM调优秘籍:把你的Java程序调教成性能怪兽!

Java版本迁移工具EMT4J

Alibaba Dragonwell JDK

java -XX:+PrintFlagsFinal -version 是一个非常有用的 JVM 调试和诊断命令,主要用于查看当前 JVM 启动时所有参数的最终生效值(包括默认值和用户覆盖值)。

JDK 8 4C8G 参考

-server \
-Xms4g \
-Xmx4g \
-XX:MetaspaceSize=256m \
-XX:MaxMetaspaceSize=512m \
-XX:+UseConcMarkSweepGC \
-XX:+CMSScavengeBeforeRemark \
-XX:CMSMaxAbortablePrecleanTime=5000 \
-XX:+CMSClassUnloadingEnabled \
-XX:CMSInitiatingOccupancyFraction=75 \
-XX:+UseCMSInitiatingOccupancyOnly \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=4 \
-Xloggc:logs/gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCDateStamps \
-XX:+UseGCLogFileRotation \
-XX:NumberOfGCLogFiles=5 \
-XX:GCLogFileSize=10M \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=256m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=logs/heapdump.hprof \
-XX:ErrorFile=logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \
-server \
-Xms4g \
-Xmx4g \
-XX:MetaspaceSize=256m \
-XX:MaxMetaspaceSize=512m \
-XX:MaxNewSize=2g \
-XX:+UseG1GC \
-XX:InitiatingHeapOccupancyPercent=40 \
-XX:G1HeapRegionSize=8m \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=4 \
-Xloggc:logs/gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCDateStamps \
-XX:+UseGCLogFileRotation \
-XX:NumberOfGCLogFiles=5 \
-XX:GCLogFileSize=10M \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=256m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=logs/heapdump.hprof \
-XX:ErrorFile=logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \

JDK 8 8C16G

-server \
-Xms10g \
-Xmx10g \
-Xmn5g \
-XX:MetaspaceSize=512m \
-XX:MaxMetaspaceSize=512m \
-XX:+UseConcMarkSweepGC \
-XX:+CMSScavengeBeforeRemark \
-XX:CMSMaxAbortablePrecleanTime=5000 \
-XX:+CMSClassUnloadingEnabled \
-XX:CMSInitiatingOccupancyFraction=75 \
-XX:+UseCMSInitiatingOccupancyOnly \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=8 \
-Xloggc:logs/gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCDateStamps \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=512m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=logs/heapdump.hprof \
-XX:ErrorFile=logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \
-server \
-Xms10g \
-Xmx10g \
-XX:MetaspaceSize=512m \
-XX:MaxMetaspaceSize=512m \
-XX:MaxNewSize=5g \
-XX:+UseG1GC \
-XX:InitiatingHeapOccupancyPercent=40 \
-XX:G1HeapRegionSize=16m \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=8 \
-Xloggc:logs/gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCDateStamps \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=512m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=logs/heapdump.hprof \
-XX:ErrorFile=logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \

JDK 11

# 4C8G
-server \
-Xms4g \
-Xmx4g \
-XX:MetaspaceSize=256m \
-XX:MaxMetaspaceSize=256m \
-XX:+UseG1GC \
-XX:G1HeapRegionSize=8m \
-XX:+G1BarrierSkipDCQ \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=4 \
-Xlog:gc*:logs/gc.log \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=256m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/app/logs/heapdump.hprof \
-XX:ErrorFile=/home/admin/logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \

# 8C16G
-server \
-Xms8g \
-Xmx8g \
-XX:MetaspaceSize=512m \
-XX:MaxMetaspaceSize=512m \
-XX:+UseG1GC \
-XX:G1HeapRegionSize=16m \
-XX:+G1BarrierSkipDCQ \
-XX:+ExplicitGCInvokesConcurrent \
-XX:ParallelGCThreads=8 \
-Xlog:gc*:logs/gc.log \
-Dsun.rmi.dgc.server.gcInterval=2592000000 \
-Dsun.rmi.dgc.client.gcInterval=2592000000 \
-XX:ReservedCodeCacheSize=512m \
-XX:MaxDirectMemorySize=512m \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=logs/heapdump.hprof \
-XX:ErrorFile=/home/admin/logs/hs_err_pid%p.log \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Asia/Shanghai \
-Djava.security.egd=file:/dev/./urandom \