Searching for bukkit memory leaks

In this post I will describe how to search for memory leaks in your bukkit minecraft SMP server.

Getting a heap dump

The first step is to obtain a java heap dump to inspect. This is a nice article on the subject:
http://blog.emptyway.com/2007/04/02/finding-memory-leaks-in-java-apps/

That article describes some different ways to obtain a heap dump. If you are using a JDK version of java instead of an JRE, you have some neat tools at your disposal :). For example hprof and jmap.

However none of those tools work well together with bukkit. The tool jmap hangs the minecraft server and then crashes it. The tool hprof makes the server slow down to a crawl.

So we are going to use another method. We will instruct java to dump the heap if the application (bukkit) runs out of memory. We do this by passing some additional arguments when starting the server:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp

Your command could now look like this:

java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Xms3G -Xmx3G -jar craftbukkit-0.0.1-SNAPSHOT.jar

Now you should run your server till it crashes. The out of memory errors on my server looks something like this:

java.lang.OutOfMemoryError: GC overhead limit exceeded

And after the crash I have a file named “/tmp/java_pid1577.hprof”. This is the heap dump we want to analyze. In order to do that I transfer it to my desktop computer using FileZilla. You would might want to compress the file before you transfer it. My file was 2.5 gigabytes so I compressed it to 186 megabytes before transfering it (6% compressions ratio :O)

gzip -9 java_pid1577.hprof

Analyzing the heap dump

You can now download this heap dump to your own computer and analyze it. Here are some nice free tools for doing just that:

3 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>