How do you determine a good MaxPermSize?
I know I'll probably get beat up for not knowing my JVM Turning parameters. I admit that I should know them better than I do. Hopefully this post will help us all understand them a bit better.
Ever since I upgraded appfuse.org to AppFuse 1.9.1, it's been experiencing OOM issues. They've been so bad that the site is lucky if it stays up for more than an hour. I've done a fair amount of performance testing on a single AppFuse application (and gotten very good numbers), so I was pretty puzzled by the whole situation.
To reproduce the problem, I downloaded all 5 demos to my machine and began profiling with JProfiler. Nothing stood out, but I was able to reproduce the problem by clicking through all the different applications. While testing, I had my JAVA_OPTS set to -Xms256M -Xmx384M.
After staring at JProfiler for hours, I gave up and sent my findings to the AppFuse mailing list. After going back and forth with several ideas, Sanjiv came up with the winner.
Did you try increasing the max perm size (-XX:MaxPermSize=256m)? Max Perm size is running out of memory and not necessarily the main memory. Class metadata stuff is placed in the perm memory (google for more details) and since we're using Spring, Hibernate and Tapestry which all use a lot of reflection, proxying etc, it's not surprising that max perm size is running out of memory.
Based on his advice, I added -XX:MaxPermSize=256m to my JAVA_OPTS, fired up JProfiler/Tomcat and began hammering my local instance with WAPT. 15 minutes later, with 20 simultaneous users, the heap and memory were humming along nicely with no issues. I made the change on appfuse.org and it's been up every since.
This experience has motivated me to start adding "-XX:MaxPermSize=256m" to all my JAVA_OPTS. Is this a good idea? If so, is 256m a good value to use? If not, what's the best way to determine (or guess) the proper value for this setting?
Posted by Stephen Duncan Jr on April 19, 2006 at 05:10 PM MDT #
Posted by guillaume carré on April 19, 2006 at 05:11 PM MDT #
The combination of these two flags will allow you to see how much GC is happening, which generations are taking up how much memory, and yes, how much the PermGen is taking up. You should watch your running applications over a period of time to see how they handle memory in order to get a real idea of what GC flags to use.
-M
Posted by Moazam on April 19, 2006 at 05:49 PM MDT #
Posted by Matthew Fleming on April 19, 2006 at 05:56 PM MDT #
Posted by Peter Thistleton on April 19, 2006 at 07:12 PM MDT #
Posted by gerryg on April 19, 2006 at 10:33 PM MDT #
Posted by Moazam Raja on April 19, 2006 at 11:50 PM MDT #
Posted by Michael Neale on April 20, 2006 at 05:45 AM MDT #
Posted by Henrik Ståhl on April 20, 2006 at 06:03 AM MDT #
Posted by Michael Neale on April 20, 2006 at 06:49 AM MDT #
Posted by Henrik Ståhl on April 20, 2006 at 07:04 AM MDT #
Incidentally, and this is obvious, but if you just upgraded the software and the OOM errors just started, you can bet that you're abusing memory somewhere in the new release.
Posted by Bruce Snyder on April 20, 2006 at 09:44 AM MDT #
Posted by michael on April 20, 2006 at 12:23 PM MDT #
Yeah, but unfortunately nothing has really changed in AppFuse - except for upgrades to Tapestry 4.0 and WebWork 2.2. I suspect that Hivemind and WebWork's tighter integration with Spring might be eating up more memory. Regardless, the site has been up ever since I made this change. So regardless of what's happening, increasing the MaxPermSize fixes it.
Posted by Matt Raible on April 21, 2006 at 12:09 AM MDT #
Posted by Lee on April 24, 2006 at 09:24 AM MDT #
http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4957990
This can be solved by
Posted by Chandra Poluru on April 27, 2006 at 03:37 PM MDT #
There were however some learnings on the way:
1. Put JDBC driver in common/lib (as tomcat doku says) and never ever in WEB-INF/lib - If you get No suitable driver Exception during redeploy use JNDI DB definition in META-INF/context.xml; not in server.xml and not in conf/Catalina/localhost/<context>.xml. This is how my META-INF/context.xml looks like:
2. Don't put commons-logging into WEB-INF/lib since tomcat already bootstraps it
3. If you still run in Perm Gen Space OOM then you may have to increase Perm Gen Space or don't redeploy your webapps so fast! What was most irritating for me after thinking the issue is solved for me was that sometimes i did ran into Perm Gen Space OOM and sometimes not. It seems that gc cleans Perm Gen Space from time to time and not (!) if space is low or app explicitly requests gc. - But this I didn't fully understand (not to say not at all), but still there are reasonable arguments on sun bug database to increase this memory (see post above)
Now I'm happy again after two (!) days of reading lots of forum threads, learning lots about class loader, tomcat, spring, hibernate, aop and class metadata and knowing that programming still can be very difficult!
Posted by Yan Hackl-Feldbusch on June 29, 2006 at 08:08 AM MDT #
Posted by iniya on February 19, 2007 at 05:31 AM MST #
Posted by Matt Raible on February 19, 2007 at 05:34 AM MST #
Posted by Patrick Dezenzio on October 30, 2007 at 03:56 PM MDT #
Posted by Maarten Brugman on January 17, 2008 at 01:42 PM MST #