Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure GC to not stop the world?

Suppose I have a JVM 1.7, which runs normally with 1G max. heap size. and uses only ~0.5G of heap.

At some moment the heap usage steeply increased in few minutes (I suspect increased load not a memory leak) and GC (PS MarkSweep) started. The GC was running for about 30 min. and the server did not respond all that time.

The heap stats shows that at that moment Old Gen heap usage increased, Eden decreased, and max Survivor increased too.

The JVM uses default option -XX:+UseParallelGC

I will try to increase the heap, limit the input data size, etc. However I wonder how I can tune the GC to not "stop the world" for half an hour. I don't mind if the server slows down but I do not want it to stop responding at all.

How to configure GC to not stop the world ?

like image 997
Michael Avatar asked Dec 29 '25 02:12

Michael


1 Answers

While you can't have guarantees (unless you are on VM like Zing) you can give soft goals to GC which it will try to achieve. See more here. Oracle Technetwork. pt. Ergonomics

XX:MaxGCPauseMillis=.This is interpreted as a hint that pause times of milliseconds or less are desired; ... Note that these adjustments may cause the garbage collector to reduce the overall throughput of the application and in some cases the desired pause time goal cannot be met.

-XX:GCTimeRatio=.The throughput goal is measured in terms of the time spent doing garbage collection vs. the time spent outside of garbage collection (referred to as application time). The goal is specified by the command line option -XX:GCTimeRatio=, which sets the ratio of garbage collection time to application time to 1 / (1 + ). For example, -XX:GCTimeRatio=19 sets a goal of 1/20 or 5% of the total time in garbage collection. The default value is 99, resulting in a goal of 1% of the time in garbage collection.

PS. However, I have an opinion that if an app with 0.5Gb heap spends 30 minutes in GC there are more chances that there's something wrong with the app, not with GC itself unless you are trying to run the app on some legacy platform.

like image 110
Andrey Taptunov Avatar answered Dec 30 '25 16:12

Andrey Taptunov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!