In this article, we try to update some of those information with the focus on thread tuning.
Ergonomics for servers was first introduced in Java SE 5.0. It has greatly reduced application tuning time for server applications, particularly with heap sizing and advanced GC tuning. In many cases no tuning options when running on a server is the best tuning you can do.
Here we will focus on the number of GC worker threads chosen to run on a specific server based on the ergonomics in G1 GC.
||Worker Threads Used
In the table below, we have summarized the most important GC worker threads in Oracle's G1 GC implementation. For comparison, Parallel GC only uses ParallelGCThreads and CMS only uses ParallelGCThreads and ConcGCThreads. Be warned that these values can be changed in the future if Oracle sees appropriate.
GC thread counts are based on the number of processors (including virtual processor if hyper-threading is enabled) reported by the system. To see the number of processors you have in the system, check out the file /proc/cpuinfo. In this article, 32 processors are used in the demonstration.
|Name||Controlled by||Default if Not Specified||Description|
|Parallel GC Threads||-XX:ParallelGCThreads||if #proc <=8, then #proc;|
if #proc >8, 8+(#proc-8)*(5/8)
|Parallel Marking Threads||-XX:ConcGCThreads||There are lot of cases, but mostly it uses max((ParallelGCThreads+2)/4, 1)|
|G1 Main Concurrent Mark GC Thread||1||Master concurrent thread|
|G1 Concurrent Refinement Thread||-XX:G1ConcRefinementThreads||ParallelGCThreads+1||The +1 is the master thread which control these worker threads.|
What Are They?
G1 garbage collection cycle has multiple phases: it starts with an initial marking phase and ends with a concurrent-cleanup phase. During the cycle, there are some phases that pause all the application threads, and some that run concurrently. These GC worker threads used in G1 GC include, but not limited to:
- ParallelGCThreads are the threads employed during GC pauses
- They are responsible for copying (and scanning for) live objects during stop-the-world (or STW) pauses.
- They are also employed during other STW pauses (such as Remark and Cleanup).
- In concurrent marking, there is one controller thread and another bunch of worker threads. The number of worker threads is set using ConcGCThreads or a fraction of ParallelGCThreads if ConcGCThreads is not set.
- Worker threads are the threads used for marking and determining the liveness of regions, which are run concurrently to the application threads.
- Increasing ConcGCThreads will make the marking cycle complete faster.
- G1ConcRefinementThreads are the threads used for updating remembered set while application threads are running concurrently.
- They are responsible for taking the buffers that are used to log object updates and updating the RememberedSets (or RSets) based upon the updates.
- If G1ConcRefinementThreads is not set, then its value is ParallelGCThreads + 1.
- For example, if ParallelGCThreads is 23 then we will have 24 refinement threads.
- One is used for sampling and updating the RSets of young regions (typically young regions have less cross-region references so one thread is enough); the other 23 threads fill update buffers.
- Typically they don't all run at once.
- They each have a stepped activation threshold and a thread is activated when the number of completed buffers exceeds it's activation threshold.
- They also have deactivation thresholds and when the number of filled update buffers falls below a thread's deactivation threshold, it is deactivated.
For our server with 32 processors, the number of GC worker threads chosen by G1's ergonomics are:
- # ParallelGCThreads = 23
- # ConcGCThreads = 6
- # G1ConcRefinementThreads = 23
To find out what the GC worker thread counts are for your server, you can use -XX:+PrintFlagsFinal. You can also change the default values if you see appropriate.[6,7] For some systems, default values sometimes can be too high.
- Garbage First Garbage Collector Tuning (Published August 2013)
- Java Heap Sizing: How do I size my Java heap correctly?
- Intel® Hyper-Threading Technology
- What Are the Default HotSpot JVM Values?
- Part #1 - Tuning Java Garbage Collection for HBase
- Linux: Understanding Processor Queue in Vmstat Output
- How to Troubleshoot High CPU Usage of Java Applications?
- Getting Started with the G1 Garbage Collector
- G1: One Garbage Collector To Rule Them All
- Remembered Sets (RSets) in G1 GC
- G1 GC uses independent Remembered Sets (RSets) to track references into regions. Independent RSets enable parallel and independent collection of regions because only a region's RSet must be scanned for references into that region, instead of the whole heap. To achieve the task, G1 GC uses a post-write barrier to record changes to the heap and update the RSets.