Tuning Stop-The-World garbage collection
STW garbage collection means that the JVM stops all application
threads to carry out garbage collection through the "GCThread#*"
threads. You will want to minimize this time as these are short,
but inevitable total halts. It is reported on the VM summary page
in JConsole as "G1 Young generation".
You will be able to do some simple math from that page,
determining frequency and CPU use by STW GC. The STW time reported
there will be higher what you see from thread monitoring (e.g.
top). This is because thread
monitoring only counts time spent in the GC threads, but for the
JVM, GC time is the time when the application is stopped,
ranging from the start of the first GC thread to the last one
finishing.
You can minimize this difference (and you will want to) by
running STW GC at highest priority. Example for Linux:
while read pid _
do
sudo renice -20 $pid &>
/dev/null
done < <(ps hH -e -o 'tid comm' | grep "GC Th")
Next thing to tune
is the number of GC threads. By default the JVM starts as many
GC threads as it sees processors available (unless > 8). The
GC threads operate more efficiently (using less total CPU time)
when they have a large chunk of memory to work on. So will you
first want to allocate enough heap memory. If you allocate too
much, intervals between garbage collections will be very long,
but also the time of the STW pause will be longer than desired.
Setting heap memory to a value that results in G1 Young
generation collections once per second is enough.
In the following cases you will want to reduce the number of GC
threads, saving CPU because now each one gets more memory
assigned :
- If you run multiple Java apps, than all but the most
important one (the I2P router) should be assigned less GC
threads, so you they do not interfere more than necessary.
- When running a hyperthreading CPU, you will notice that
already 3 concurrent threads will exhaust 4 virtual (2
physical core). So we recommend to use 3 GC threads for each
4 virtual cores.
- The Mac is different as always. You will notice on an
Quad-Core or better that für multiple parallel Java apps the
OS usually will only heat up 2 physical cores. So we suggest
to use 3 GC threads for I2P and 2 for all others.
You set the number of GC threads using:
-
"wrapper.java.additional.**=-XX:ParallelGCThreads=xxx" or
"-XX:ParallelGCThreads=xxx"
<-- Back