views:

1579

answers:

6

I've got a Grails application that does a fairly decent amount of domain object creation and destruction, and it seems to run out of PermGen space at a very, very rapid rate. I've done the usual tweaks (bumped PermGen to 256M, enabled class GC, etc.), but no dice.

Would anyone care to recommend some (and hopefully free or very low-cost) tools for troubleshooting this sort of memory consumption in Groovy and/or Java? Or some techniques that you use to troubleshoot JVM memory problems?

Edit: This is when the application is deployed inside Tomcat in production mode; I've not tried with other containers. Even so, it would be nice to have some resources for tracking down the problem.

+1  A: 

YourKit is a nice tool I have used multiple times to diagnose memory issues. It is commercial, but it has a free evaluation version available for one-shot debugging.

andri
+1  A: 

Is the problem you're having occurring in development or production?

If you're in development, remember that Grails is constantly recompiling many aspects of your application (not only Domain changes, but controller changes, and other classes as well). I have PermGen issues too, but most are triggered by the steady recompilation of the files I'm working on. You can turn this feature off

http://www.grails.org/FAQ#Q:%20OMG%20I%20get%20OutOfMemoryErrors%20or%20PermGen%20Space%20errors%20when%20running%20Grails%20in%20development%20mode.%20What%20do%20I%20do?

If you're in production, then obviously you have a much more critical problem. PermGen memory issues are attributed to many of the frameworks on which Grails is built, including Spring, Hibernate, and even Sun's own JVM. You could try tweaking the maximum heap size for your Web container (Tomcat or Jetty).

You could also try a different implementation of the JVM, like Oracle's JRockit, which is supposed to be considerably better at garbage collection and other means of efficiency. I've never tried it myself, but since I too am in the middle of developing and extensive Grails project, I may be shopping solutions to these problems myself. Good luck!

JRockit is an Oracle producthttp://www.oracle.com/technology/software/products/jrockit/index.html
I'm running in production mode on Tomcat (6.0.18), and don't really have a choice about the JVM.
Don Werve
I've read that one of the problems with garbage collection in a Web container is that the stack is only truly refreshed when the container is restarted. (Restart the container is equivalent to restarting the Tomcat service, not simply restarting a single Web application.)
+1  A: 

Eclipse Memory Analyzer is a free tool that is at least as good as Yourkit.

kohlerm
+2  A: 

I personally like VisualVM. There are definitely more powerful tools around, but this one has got a nice usability-to-power ratio.

Joachim Sauer
A: 

If this happens after you hot redeploy your application several times you may be affected by this Grails bug. The Tomcat FAQ also has several possible causes for PermGen leaks.

Ben Williams
I actually think that's the root problem (the app runs fine in Jetty), but even so I'd like to have a good resource going forward for doing this sort of debugging.
Don Werve
+3  A: 

Have you tried

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

?

Together with increasing the usual suspects (-Xmx, -Xms, -XX:PermSize and -XX:MaxPermSize) this resolved all the PermGen issues on our production Tomcat, which had occured pretty soon after deploying the app. Never seen another OOM-Exception after that. :-)

Daniel Rinser
@daniel, any performance related issues with this solution? We are using the searchable, auditable, and quartz plugins with a lot of recurrent jobs and get a PermGen OOM every week...
hvgotcodes