Column catalog

  1. Time to upgrade Java11 -01- JDK11 advantages and JDK options
  2. Time to upgrade Java11 -02- Upgrade JDK11
  3. Time to upgrade Java11 -03 VIRTUAL machine Jvm parameter Settings
  4. Http2 Clear Text (H2C)
  5. Time to update java11 – obstacles and issues with h2c communication in 05 microservices

preface

Following up on the previous two articles, today we’ll talk about Jvm parameter changes after upgrading Java11. Java11 removed the CMS garbage collector. If you upgrade to Java11 and the Jvm parameters still use CMS garbage collector parameters, the console will report an error or even fail to start.

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.
Copy the code

JAVA11 JVM startup parameters

G1GC configuration items:

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 configuration

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.

Sample configuration

-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
Copy the code

G1GC does not have to explicitly set the size of the new generation, and its automatic tuning is very reliable, often achieving the desired result after a long period of running. It is not recommended to do too much configuration, it is still necessary for GC log, you can configure according to your actual needs.

The statement

This series of articles is compiled and written by The author of micA, Ru Meng Technology. If there is any reference or reprint, please keep the original author and indicate the source.