- Loading...
Warning |
---|
Please note that ZGC is under active development, which means that the information and advice given below might change in the future. |
Table of Contents |
---|
ZGC is currently available on Linux/x86_64 and Solaris/SPARC.
The source code can be found in the ZGC project repository. Just clone, configure and make.
$ hg clone http://hg.openjdk.java.net/zgc/zgc
$ cd zgc
$ sh configure
$ make images
This will build a complete JDK for you, which includes ZGC. On Linux, the root directory of the new JDK will be found here:
./build/linux-x86_64-normal-server-release/images/jdk
And the Java launcher will be found in its usual place, here:
./build/linux-x86_64-normal-server-release/images/jdk/bin/java
Xms<size> - logging and basic tuning to improve throughput and latencyXms<size> - UseLargePagesParallelGCThreads=<threads> -XX:ConcGCThreads=<threads>JVM OptionsUse the -XX:+UseZGC
option to enable ZGC.
In general, ZGC works best when there is enough heap headroom to keep up with the allocation rate without having to run back to back GCs. With too little headroom the GC will simply not be able to keep up and Java threads will be stalled to allow the GC to catch up. Stalling of Java threads should basically be avoided at all cost by increasing the heap size (or as a secondary option, increase the number of concurrent GC threads, see below).
For optimal performance, setting the initial heap size (-Xms
) equal to the maximum heap size (-Xmx
) is generally recommended.
ZGC uses both -XX:ParallelGCThreads=<threads>
and -XX:ConcGCThreads=<threads>
to determine how many worker threads to use during different GC phases. If they are not set, ZGC will try to select an appropriate number. However, please note that the optimal number of threads to use heavily depends on the characteristics of the workload you're running, which means that you almost always want to explicitly specify these to get optimal throughput and latency. We hope to be able to remove this recommendation at some point in the future, when ZGC's heuristics for this becomes good enough, but for now it's recommended that you try different settings and pick the best one.
ParallelGCThreads
sets the level of parallelism used during pauses and hence directly affects the pause times. Generally speaking, the more threads the better, as long as you don't over provision the machine (i.e. use more threads than cores/hw-threads) or the application root set is so small that is can easily be handled by just a few threads.
The following GC phases are affected by ParallelGCThreads
:
ConcGCThreads
sets the level of parallelism used during concurrent phases. The number of threads to use during these phases is a balance between allowing the GC to make progress and not stealing too much CPU time from the application. Generally speaking, if there are unused CPUs/cores in the system, always allow concurrent threads to use them. If the application is already using all CPUs/cores, then the machine is essentially already over-provisioned and you have to allow for a throughput reduction by either letting concurrent GC threads steal/compete for CPU time, or by actively reducing the application CPU footprint.
The following GC phases are affected by ConcGCThreads
:
Example:
When running SPECjbb2015, on a two socket Intel Xeon E5-2690 machine, which a total of 2 x 8 = 16 cores (with hyper-threading, 2 x 16 = 32 HW-threads) using a 128G heap, the following options typically results in optimal throughput and latency:
-XX:+UseZGC -Xms128G -Xmx128G -XX:+UseLargePages -XX:ParallelGCThreads=20 -XX:ConcGCThreads=4
Enabling pages are on Linux/x86 and 16G 16G 2M First assign 16G "at least" part is important, since enabling the use of large pages in the JVM means that not only the GC will try to use these for the Java heap, but also that try to them , , etc we therefore 18G 2G can not hugepagesZPathZPathAn alternative to using explicit large pages (as described above) is to use transparent huge pages. Use of transparent huge pages is usually not recommended for latency sensitive applications, because it tends to cause unwanted latency spikes. However, it might be worth experimenting with to see if/how your workload is affected by it. But be aware, your mileage may vary. have the appropriate mode set in . See the kernel documentation for more information.The options above tells the JVM to issue madvise(..., MADV_HUGEPAGE)
calls for memory it mapps, which is useful when using transparent huge pages in madvise mode basic a sub-set of the CPUs in the systemStarting with JDK 9,