Setting the heap size on your JVM
Cameron has posted a comment on my Performance Tuning MySQL article. The reason I'm highlighting this because it's something I wasn't are of:
From the article:
-Xms128m -Xmx256m
The Sun JVM will run significantly faster with the following config instead:
-Xms256m -Xmx256m
That's because the Sun implementation acquires and releases memory from / to the OS way too aggresively if the "ms != mx". Furthermore, either your server has the 256MB available or it doesn't. If you don't have it available, don't set the max that high. If you do have it available, you gain nothing from setting the min lower. This isn't a desktop system, it's a server -- make sure you have the necessary resources and if you do then use them!
Time to change all my heap size setting since I've been using the first setting (128/256) for quite some time. Thanks Cameron! The real question is: will changing "-Xms256m -Xmx512m" to "-Xms512m -Xmx512m" speed up my slow-ass PowerBook? ;-)
Posted by Paul Wang on April 28, 2004 at 03:39 PM MDT #
http://developers.sun.com/dev/coolstuff/jvmstat/
Using this tool you can establish what kind of memory usage your app exhibits and look at how gc is affecting performance. Then you can tune the heap size to you heart's content.
Posted by Dan Creswell on April 28, 2004 at 04:17 PM MDT #
http://java.sun.com/docs/hotspot/gc1.4.2/index.html
It talks very specifically about how the JVM manages memory given a specific min and max and explains why the heap size varies when mx and ms are not the same.
Posted by Dan Creswell on April 28, 2004 at 05:05 PM MDT #
Posted by Unknown on April 28, 2004 at 06:56 PM MDT #
Posted by Will on April 28, 2004 at 06:56 PM MDT #
If you have a huge difference between the minimum and maximum heap size then your system will have to free up the un-referenced memory for a longer time: as a consequence your JVM blocks for a long time. If your system is powerful enough, and you don't have a real-time system, blocking of 0.5 seconds might not be an issue. This has the advantage that the GC will not run as often.
On the other hand when you are working with a mission-critical application and your system is slow then it is wise to set the minimum and maximum heap size almost equal. The result is that the GC will run more often but the each cycle will not take so long.
It is a matter of observing your application instead of a blind copy and paste from a tutorial.
The quote above is correct: the JVM will run faster but the GC will also run more often and will block your application more often, however for a very short period.
Posted by Thomas De Vos on April 28, 2004 at 09:56 PM MDT #
Posted by Peter on April 29, 2004 at 12:40 PM MDT #