views:

323

answers:

3

I am running an application server on Linux 64bit with 8 core CPUs and 6 GB memory.

The server must be highly responsive.

After some inspection I found that the application running on the server creates rather a huge amount of short-lived objects, and has only about 200~400 MB long-lived objects(as long as there is no memory leak)

After reading http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html I use these JVM options

-server -Xms2g -Xmx2g -XX:MaxPermSize=256m -XX:NewRatio=1 -XX:+UseConcMarkSweepGC

Result: the minor GC takes 0.01 ~ 0.02 sec, the major GC takes 1 ~ 3 sec the minor GC happens constantly.

How can I further improve or tune the JVM?

larger heap size? but will it take more time for GC?

larger NewSize and MaxNewSize (for young generation)?

other collector? parallel GC?

is it a good idea to let major GC take place more often? and how?

+2  A: 

You may be interested in trying the low-pause Garbage-First collector instead of concurrent mark-sweep (although it's not necessarily more performant for all collections, it's supposed to have a better worst case). It's enabled by -XX:+UseG1GC and is supposed to be really awesomesauce, but you may want to give it a thorough evaluation before using it in production. It has probably improved since, but it seems to have been a bit buggy a year ago, as seen in Experience with JDK 1.6.x G1 (“Garbage First”)

gustafc
+1  A: 

Result: the minor GC takes 0.01 ~ 0.02 sec, the major GC takes 1 ~ 3 sec the minor GC happens constantly.

Unless you are reporting pauses, I would say that the CMS collector is doing what you have asked it to do. By definition, CMS will use a larger percentage of the CPU than the Serial and Parallel collectors. This is the penalty you pay for low pause times.

If you are seeing 1 to 3 second pause times, I'd say that you need to do some tuning. I'm no expert, but it looks like you should start by reducing the value of CMSInitiatingOccupancyFraction from the default value of 92.

Increasing the heap size will improve the "throughput" of the GC. But if your problem is long pauses, increasing the heap size is likely to make the problem worse.

Stephen C
A: 

It is perfectly fine for the garbage collection to run in parallel with your program, if you have plenty of cpu, which you do.

What you want, is to make absolutely certain that you will not run into a scenario where the garbage collection PAUSES your main program.

Have you tried simply not stating any flags except saying you want the server VM (for the Sun JVM), and then put your server under heavy load to see how it behaves? Only then can you see, if you get any improvements from tinkering with options.

Thorbjørn Ravn Andersen