Skip to content
Advertisement

How to properly set the G1GC options for a server with 22G heap

I’m setting up a new JAVA server, the heap size is set to 22G, and would use the G1GC algorithm. I’ve read all the oracle documents, and believe this is what we need, but still have a few questions:

1> What -XX:G1HeapRegionSize should be ? Must the number be a power of two? If so, should I set 8M to get 2816 regions, or set 16M to get 1408 regions ?

2> Do you think we should explicitly set -XX:ParallelGCThreads and -XX:ConcGCThreads ? If they are omitted, will they be set to a default number according to the server logical processors ? Or just be set to a fixed number ?

3> What about the below options, is there anything I missed ? Since it’s the first time we use the G1GC, so I’ve no idea if we need set other G1 related options, since they all have a recommended default value. (described in https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc_tuning.html)

// common options

-Xms22G -Xmx22G -Xss1024K

// G1 options

-XX:+UseG1GC -XX:MaxGCPauseMillis=500 -XX:G1HeapRegionSize=16

// logs

-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps

-XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:-PrintCommandLineFlags

4> Do you think it possible to do the things roughly right for the first time? I mean without memory overflow or exhausted. Or do you think we will always have to tune the parameters more carefully to get things right for several times ?

5> Any other suggestions ?

It’s a bit long, thanks for your reading. Any help will be much appreciate. Thank you!

Advertisement

Answer

Quoting from the document you linked to:

The G1 GC is an adaptive garbage collector with defaults that enable it to work efficiently without modification.

So, the most obvious suggestion … based on the documentation itself … is to run the JVM without any GC tuning. Just give it the heap size, and select the GC:

-Xmx22G -XX:+UseG1GC

The G1GC is designed so that you can use it that way and get good performance.

If it works well enough, that’s all you need to do. If you see performance problems, then start looking into tuning … based on the nature of the problems that you are seeing.

Tuning just for the sake of it is a waste of time.

Tuning when you don’t (yet) have any idea of the performance problems is a bit like target shooting with a blindfold on. You are liable to make things worse than if you did nothing.

Finally, the “optimal” GC settings will depend on various aspects of your application and your workload, and the goal of your tuning. Anything we might suggest would be pure guesswork.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement