「是时候升级java11了」虚拟机Jvm参数设置

专栏目录

  1. 是时候升级java11了-01-jdk11优势和jdk选择
  2. 是时候升级java11了-02-升级jdk11踩坑记
  3. 是时候升级java11了-03虚拟机Jvm参数设置
  4. 是时候升级java11了-04微服务内http2通信之http2 Clear Text(h2c)
  5. 是时候升级java11了-05微服务内h2c通信的阻碍和问题解决

前言

紧接前2篇文章,我们今天来聊聊升级 Java11 之后的一写 Jvm 参数变化。Java11 删除掉了 cms 垃圾回收器,如果你升级到了 Java11 但是 Jvm 参数仍然使用 cms 垃圾回收器参数时控制台会报错,甚至会启动失败。

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Unrecognized VM option 'ParallelCMSThreads=2'
Did you mean 'ParallelGCThreads=<value>'? Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.复制代码

JAVA11 JVM 启动参数

G1GC 配置项:

Option and Default Value
Description
-XX:+UseG1GC
Use the Garbage First (G1) Collector
-XX:MaxGCPauseMillis=n
Sets a target for the maximum GC pause time. This is a soft goal, and the JVM will make its best effort to achieve it.
-XX:InitiatingHeapOccupancyPercent=n Percentage of the (entire) heap occupancy to start a concurrent GC cycle. It is used by GCs that trigger a concurrent GC cycle based on the occupancy of the entire heap, not just one of the generations (e.g., G1). A value of 0 denotes 'do constant GC cycles'. The default value is 45.
-XX:NewRatio=n
Ratio of old/new generation sizes. The default value is 2.
-XX:SurvivorRatio=n
Ratio of eden/survivor space size. The default value is 8.
-XX:MaxTenuringThreshold=n
Maximum value for tenuring threshold. The default value is 15.
-XX:ParallelGCThreads=n
Sets the number of threads used during parallel phases of the garbage collectors. The default value varies with the platform on which the JVM is running.
-XX:ConcGCThreads=n
Number of threads concurrent garbage collectors will use. The default value varies with the platform on which the JVM is running.
-XX:G1ReservePercent=n
Sets the amount of heap that is reserved as a false ceiling to reduce the possibility of promotion failure. The default value is 10.
-XX:G1HeapRegionSize=n
With G1 the Java heap is subdivided into uniformly sized regions. This sets the size of the individual sub-divisions. The default value of this parameter is determined ergonomically based upon heap size. The minimum value is 1Mb and the maximum value is 32Mb.

G1GC log 配置详细说明:

G1GC -Xlog:gc
Log messages with gc tag using info level to stdout, with default decorations.
G1GC -Xlog:gc,safepoint
Log messages with either gc or safepoint tags (exclusive), both using 'info' level, to stdout, with default decorations.
G1GC -Xlog:gc+ref=debug
Log messages with both gc and ref tags, using debug level, to stdout, with default decorations.
G1GC -Xlog:gc=debug:file=gc.txt:none
Log messages with gc tag using debug level to file gc.txt with no decorations.
G1GC -Xlog:gc=trace:file=gc.txt:uptimemillis, pids:filecount=5,filesize=1m Log messages with gc tag using trace level to a rotating logs of 5 files of size 1MB, using the base name gc.txt, with uptimemillis and pid decorations.
G1GC -Xlog:gc::uptime,tid
Log messages with gc tag using info level to output stdout, using uptime and tid decorations.
G1GC -Xlog:gc*=info,safepoint*=off
Log messages with at least gc using info level, but turn off logging of messages tagged with safepoint.

示例配置

-server
-Xmx4g
-Xms4g
-Xss256k
-XX:MaxDirectMemorySize=256m
-XX:+UseG1GC 
-XX:+UseCompressedOops 
-XX:+UseCompressedClassPointers
-XX:+SegmentedCodeCache 
-verbose:gc
-XX:+PrintCommandLineFlags
-XX:+ExplicitGCInvokesConcurrent
-Djava.security.egd=file:/dev/./urandom
-Xlog:gc*,safepoint:/data/log/${SERVICE_NAME}/gc.log:time,uptime:filecount=100,filesize=50M复制代码

G1GC 不必明确设置新生代大小,其自动调优也十分可靠,对于停顿时间往往在长时间运行后可以达到预期效果。不建议进行过多的配置,对于 gc log 笔者认为还是很有必要,各位同学可以按照自己的实际需求进行配置。

声明

本系列文章由微服务核心组件mica作者如梦技术整理撰写,如有参考或者转载,请保留原作者和注明出处。image

猜你喜欢

转载自juejin.im/post/5e572e226fb9a07cd00d8446