Java Reference
In-Depth Information
▪ Collection of the old generation when using -XX:+UseParallelOldGC
▪ Collection of the young generation when using -XX:+UseParNewGC
▪ Collection of the young generation when using -XX:+UseG1GC
▪ Stop-the-world phases of CMS (though not full GCs)
▪ Stop-the-world phases of G1 (though not full GCs)
Because these GC operations stop the application threads from executing, the JVM attempts
to use as many CPU resources as it can in order to minimize the pause time. By default, that
means the JVM will run one thread for each CPU on a machine, up to eight. Once that
threshold has been reached, the JVM only adds a new thread for every five-eighths of a CPU.
So the total number of threads (where N is the number of CPUs) on a machine with more
than eight CPUs is:
ParallelGCThreads = 8 + ((N - 8) * 5 / 8)
There are times when this number is too large. An application using a small heap (say, 1 GB)
on a machine with eight CPUs will be slightly more efficient with four or six threads divid-
ing up that heap. On a 128-CPU machine, 83 GC threads is too many for all but the largest
heaps.
Additionally, if more than one JVM is running on the machine, it is a good idea to limit the
total number of GC threads among all JVMs. When they run, the GC threads are quite effi-
cient and each will consume 100% of a single CPU (this is why the average CPU usage for
the throughput collector was higher than expected in previous examples). In machines with
eight or fewer CPUs, GC will consume 100% of the CPU on the machine. On machines with
more CPUs and multiple JVMs, there will still be too many GC threads running in parallel.
Take the example of a 16-CPU machine running four JVMs; each JVM will have by default
13 GC threads. If all four JVMs execute GC at the same time, the machine will have 52
CPU-hungry threads contending for CPU time. That results in a fair amount of contention; it
will be more efficient if each JVM is limited to four GC threads. Even though it may be un-
likely for all four JVMs to perform a GC operation at the same time, one JVM executing GC
with 13 threads means that the application threads in the remaining JVMs now have to com-
pete for CPU resources on a machine where 13 of 16 CPUs are 100% busy executing GC
tasks. Giving each JVM four GC threads provides a better balance in this case.
Search WWH ::




Custom Search