Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long GC pauses in application

I am currently running an application which requires a maximum heap size of 16GB.

Currently I use the following flags to handle garbage collection.

-XX\:+UseParNewGC, -XX\:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=50, -XX\:+DisableExplicitGC, -XX\:+PrintGCDateStamps, -XX\:+PrintGCDetails, -Xloggc\:/home/user/logs/gc.log

However, I have noticed that during some garbage collections, the application locks up for a few seconds and then carries on - This is completely unacceptable as it's a game server.

An exert from my garbage collection logs can be found here.

Any advice on what I should change in order to reduce these long pauses would be greatly appreciated.

like image 684
Gontroller Avatar asked Mar 29 '13 02:03

Gontroller


People also ask

What causes long GC pause?

Garbage collection (GC) is the process by which Java removes data that is no longer needed from memory. A garbage collection pause, also known as a stop-the-world event, happens when a region of memory is full and the JVM requires space to continue.

How do I fix long garbage collection time?

One way is to increase the Java heap size. Look at the Garbage Collection subtab to estimate the heap size used by the application and change Xms and Xmx to a higher value. The bigger the Java heap, the longer time it is between GCs.

What is GC pause duration?

Metronome garbage collector (GC) pause time can be fine-tuned for each Java™ process. By default, the Metronome GC pauses for 3 milliseconds in each individual pause, which is known as a quantum.

Why does Major GC take so long?

Large Heap size Large heap size (-Xmx) can also cause long GC pauses. If heap size is quite high, then more garbage will be get accumulated in the heap. When Full GC is triggered to evict the all the accumulated garbage in the heap, it will take long time to complete.


2 Answers

Any advice on what I should change in order to reduce these long pauses would be greatly appreciated.

The chances are that the CMS GC cannot keep up with the amount of garbage your system is generating. But the work that the GC has to perform is actually more closely related to the amount of NON-garbage that your system is retaining.

So ...

  • Try to reduce the actual memory usage of your application; e.g. by not caching so much stuff, or reducing the size of your "world".
  • Try to reduce the rate at which your application generates garbage.
  • Upgrade to a machine with more cores so that there are more cores available to run the parallel GC threads when necessary.

To Mysticial:

Yes in hindsight, it might have been better to implement the server in C++. However, we don't know anything about "the game". If it involves a complicated world model with complicated heterogeneous data structures, then implementing it in C++ could mean that that you replace the "GC pause" problem with the problem that the server crashes all the time due to problems with the way it manages its data structures.

like image 85
Stephen C Avatar answered Oct 15 '22 12:10

Stephen C


Looking at your logs, I don't see any long pauses. But young GC is very frequent. Promotion rate is very low though (most garbage cleared by young GC as it should). At same time your old space utilization is low.

BTW are we talking about minecraft server?

To reduce frequency of young GC you should increase its size. I would suggest start with -XX:NewSize=8G -XX:MaxNewSize=8G

For such large young space, you should also reduce survivor space size -XX:SurvivorRatio=512

GC tuning is a path of trial and errors, so you may need some more iterations and tweaking.

You can find couple of useful articles at mu blog

  • HotSpot JVM GC options cheatsheet
  • Understanding young GC pauses in HotSpot JVM
like image 34
Alexey Ragozin Avatar answered Oct 15 '22 12:10

Alexey Ragozin