Tuesday, June 26, 2007

Perm gen size and Grails

I've been continuing to work with the Grails framework and found an interesting issue. When working with the Tomcat application server I run into several issues related to out of memory errors with Grails applications.

Attempts to resolve this with -Xmx512m or some other setting for the memory heap size failed to work. This seems to be due to the large number of elements (controllers, domains, etc) in my grails app that load classes. I believe this is related to issues of lots of use of reflection (not sure). It does appear that this memory is alive during the entire life of the application (not garbage collected). After installing several plug-ins and increasing the size of the application quite a bit this occurred. It also seems to be partly related to the creation of an additional "Context Path" for an application in Tomcat.

I found some reference to Tomcat 6 having better "perm size" management on the net vs Tomcat 5 series. Though nothing of a definitive nature. I saw it seems related since it removing the extra "Context Path" for this grails application seemed to resolve things. Perhaps it is an issue with grails applications in multiple Context Path's but the perm gen size increase did resolve it cleanly.

My current options line for catalina.sh:
JAVA_OPTS='-Xmx512m -XX:MaxPermSize=256m -server -Djava.awt.headless=true'