Announcement Announcement Module
Collapse
No announcement yet.
Embedded Tomcat running into Out of Memory Error.. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Embedded Tomcat running into Out of Memory Error..

    Hi,

    Recently upgraded my app to use Grails version from 1.0.5 to 1.3.7.

    Along with all other changes, the server running in dev environment changed from Jetty to Tomcat.

    My issue is the application is consistently running into OutOfMemoryError and this occurs only in dev environment.

    This has never happened with the the Jetty server or does not happen in WAR deployed mode in externally installed Tomcat 6.0.18 on same dev machine.


    The error is reproducible by creating/updating very few objects and navigating pages.

    So can anyone shed a light on how to configure the embedded Tomcat memory settings ?

    And to make the dev and war environment consistent, how do I set grails run-app command to use external Tomcat server ?


    The followings are 2 example error stack traces:

    1.
    2011-08-02 09:42:52,139 [http-8080-6] ERROR [/SafetySystem].[grails] - Servlet.service() for servlet grails threw exception
    java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:141)
    at groovy.lang.GroovyClassLoader.access$300(GroovyCla ssLoader.java:55)
    at groovy.lang.GroovyClassLoader$ClassCollector.creat eClass(GroovyClassLoader.java:519)
    at groovy.lang.GroovyClassLoader$ClassCollector.onCla ssNode(GroovyClassLoader.java:536)
    at groovy.lang.GroovyClassLoader$ClassCollector.call( GroovyClassLoader.java:540)
    at org.codehaus.groovy.control.CompilationUnit$12.cal l(CompilationUnit.java:757)
    at org.codehaus.groovy.control.CompilationUnit$12.cal l(CompilationUnit.java:765)
    at org.codehaus.groovy.control.CompilationUnit$12.cal l(CompilationUnit.java:765)
    at org.codehaus.groovy.control.CompilationUnit$12.cal l(CompilationUnit.java:765)
    at org.codehaus.groovy.control.CompilationUnit.applyT oPrimaryClassNodes(CompilationUnit.java:942)
    at org.codehaus.groovy.control.CompilationUnit.doPhas eOperation(CompilationUnit.java:519)
    at org.codehaus.groovy.control.CompilationUnit.proces sPhaseOperations(CompilationUnit.java:497)
    at org.codehaus.groovy.control.CompilationUnit.compil e(CompilationUnit.java:474)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyC lassLoader.java:306)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyCla ssLoader.java:287)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyCla ssLoader.java:267)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyCla ssLoader.java:214)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.compileGroovyPage(GroovyPagesTemplate Engine.java:640)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.buildPageMetaInfo(GroovyPagesTemplate Engine.java:590)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplate(GroovyPagesTemplateEng ine.java:493)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplateWithResource(GroovyPage sTemplateEngine.java:473)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplate(GroovyPagesTemplateEng ine.java:246)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplateForUri(GroovyPagesTempl ateEngine.java:373)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplateForUri(GroovyPagesTempl ateEngine.java:345)
    at org.codehaus.groovy.grails.web.pages.GroovyPagesTe mplateEngine.createTemplate(GroovyPagesTemplateEng ine.java:262)
    at org.codehaus.groovy.grails.web.servlet.view.Groovy PageView.renderWithTemplateEngine(GroovyPageView.j ava:146)
    at org.codehaus.groovy.grails.web.servlet.view.Groovy PageView.renderMergedOutputModel(GroovyPageView.ja va:81)
    at org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1047)




    2.
    org.codehaus.groovy.grails.web.servlet.mvc.excepti ons.ControllerExecutionException: Executing action[listCompanyLevel] of controller [RemindersController] caused exception: java.lang.OutOfMemoryError: PermGen space

    at java.lang.Thread.run(Thread.java:619)

    Caused by: org.codehaus.groovy.runtime.InvokerInvocationExcep tion: java.lang.OutOfMemoryError: PermGen space

    ... 1 more

    Caused by: java.lang.OutOfMemoryError: PermGen space

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)

    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)

    at java.security.AccessController.doPrivileged(Native Method)

    at CourseAttendance$findAllUpcomingItemsBetween.call( Unknown Source)

    at RemindersController.getUpcomingItems(RemindersCont roller.groovy:154)
    Last edited by lighter; Aug 1st, 2011, 09:07 PM.

  • #2
    With the run-war command you can add this configuration option:
    Code:
    grails.tomcat.jvmArgs = ["-Xmx1024m", "-XX:MaxPermSize=256m"]
    For run-app, you can set a GRAILS_OPTS environment variable:
    Code:
    export GRAILS_OPTS="-XX:MaxPermSize=256m -Xmx512m"
    But it only takes a few internal server restarts, for example if you modify a domain class, to run into the PermGen issue I'm afraid. The reloading mechanism has changed completely in Grails 2.0, partly to solve this problem.

    Comment


    • #3
      Thanks for your reply, pled.

      Good to hear that Grails 2.0 will have some memory related improvements.

      After a bit more testing, I realised that the out of memory error happens only when the dev server is started via my IDE(NetBeans).
      So there is no problem when executing "grails run-app" in command line.

      I have tried setting system variable, JAVA_OPTS and GRAILS_OPTS with the following VM args but it didn't have any affect:
      -Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m

      Setting the same VM args in the "VM Options" field in NetBeans project properties has solved the issue.


      Bytheway, do you know of any way to use the externally installed tomcat server instead of the embedded one for development ?

      Comment


      • #4
        No, sorry. You can only deploy a WAR file to the external Tomcat server. I guess you could configure the Tomcat to load web apps from an 'exploded WAR' directory that you populate with "grails -Dgrails.war.exploded=true war", but you wouldn't get reloading.

        Comment


        • #5
          ok thanks for your help.

          Comment

          Working...
          X