「是時候升級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 垃圾回收器參數時控制檯會報錯,甚至會啓動失敗。java

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 筆者認爲仍是頗有必要,各位同窗能夠按照本身的實際需求進行配置。git

聲明

本系列文章由微服務核心組件mica做者如夢技術整理撰寫, 若有參考或者轉載,請保留原做者和註明出處。 dom

image
相關文章
相關標籤/搜索