7

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.

5
  • 5
    I believe this is one of the reasons why many people prefer C++ over Java for real-time games. But don't take my word for it... Commented Mar 29, 2013 at 2:57
  • Can you provide some specific lines that had long gc pauses? Rather than expecting readers to hunt through the log file for the lines Commented Mar 29, 2013 at 3:04
  • I prefer to use off heap memory for anything over 1 GB. Off heap memory is more difficult to code for but has little impact on GC pause times. Commented Mar 29, 2013 at 7:32
  • Here is a graphical representation of my GC log. gontroller.com/caps/5e92647305.png Any comments on this? Commented Mar 29, 2013 at 23:27
  • "This is completely unacceptable as it's a game server." - Well given that we have established that this is Minecraft which is proprietary software, if the behavior is unacceptable you should be complaining to the vendor :-) Commented Nov 24, 2020 at 6:10

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I didn't mean to bash Java. C++ and Java are just different tools for different things.
The game the server is running is 'Minecraft' if that helps at all.
Ah ... so basically, your question is about how to tune Minecraft. Not really a programming problem at all. You will get better answers for this on the Minecraft formums I think.
3

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

Comments

2

I'm not an expert on Java garbage collection, but it looks like you're doing the right thing by using the concurrent collector (the UseConcMarkSweepGC flag), assuming the server has multiple processors. Follow the suggestions for troubleshooting at http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#cms. If you already have, let us know what happened when you tried them.

Comments

1

Which version of java are you using?http://docs.oracle.com/javase/7/docs/technotes/guides/vm/G1.html For better try to minimize the use of instance variables in a class.It would be better to perform on local variables than instance varibles .It helps in gaining the performance and safe from synchronization problem.In the end of operation before exit of program always reset the used variables if you are using instance variables and set again when it is required. It helps more in enhancing performance.Besides in the version of java a good garbage collection policy is implemented.It would be better to move to new version if that is fleasible. Also you can monitor the garbage collector pause time via VisualVm and you can get more idea when it is performing more garbage collection.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.