Recent Posts

RSS Feeds

Grails 1.1 and Groovy 1.6 Java JVM memory settings and tuning

In this post I want to answer the following questions:

  • Where are the Java / JVM memory settings hidden in Grails 1.1 and Groovy 1.6 and how do you change them?
  • What are the differences between the latest and older versions?
  • Are there differences I should know off between Linux and Windows?

Grails 1.1 and Grails 1.0.2 JVM memory settings

If you run the grails command it'll run $GRAILS_HOME/bin/startGrails on Linux/Unix and $GRAILS_HOME/bin/startGrails.bat on Windows. These scripts differ in their behaviour between Linux and Windows and the settings differ between the Grails versions on Windows:

  • Grails 1.1 on Linux: "server" JVM with 512 Mb maximum heap space, even if you set $JAVA_OPTS different
  • Grails 1.0.2 on Linux: same as above
  • Grails 1.1 on Windows: if $JAVA_OPTS is not set, then use 512 Mb maximum heap space and select the JVM engine automatically
  • Grails 1.0.2 on Windows: if $JAVA_OPTS is not set, then use 128 Mb maximum heap space and select the JVM engine automatically

From my point of view the best behaviour at the moment is from Grails 1.1 on windows and it should be consistent with Linux/Unix. If I set $JAVA_OPTS for good reasons I don't want it secretly be changed. I don't know what a JVM does if it gets a '-Xmx512m" and a "-Xmx256m" parameter. Use the first, the last or stop with an error?

 So I changed the startGrails command as follows on my Linux system:

# comment the old setting
# JAVA_OPTS="-server -Xmx512M $JAVA_OPTS"
# check for $JAVA_OPTS instead:
if [ "$JAVA_OPTS" == "" ]; then
    JAVA_OPTS="-server -Xmx512m"
fi

But beware: If you deploy your Grails application as a war archive on an application server this memory settings are no longer used, instead the memory settings of the application server are relevant for your app.

Groovy 1.6 JVM memory settings

If you run the groovy command it'll run $GROOVY_HOME/bin/startGroovy on Linux/Unix and $GROOVY_HOME/bin/startGroovy.bat on Windows. These scripts differ in their behaviour between Linux and Windows but they behave the same in Groovy version 1.6 as in version 1.5.7. Here are the diffference:

  • Groovy 1.6 on Linux: $JAVA_OPTS are used as they are, JVM defaults are used if $JAVA_OPTS is empty / not set
  • Groovy 1.6 on Windows: $JAVA_OPTS are used as they are, 128 Mb maximum heap space is set if $JAVA_OPTS is empty / not set

You may change the memory settings for all Groovy applications independently from other Java applications by setting the $JAVA_OPTS in the file $HOME/.groovy/startup which is read by the startGroovy script and evaluated as a shell script if it exists.

Setting JVM memory in Open Source Java Application Servers

Paul Gu wrote in his blog about "6 Common Errors in Setting Java Heap Size" including not only a nice list of traps and typical errors in setting the heap size option, but furthermore many hints where to find the heap size and $JAVA_OPTS settings for different Java applications including many Open Source Java application servers. May these help you in deploying your Grails application on one of these and tuning your JVM memory settings.


  Share

Permalink    

Related Articles:

Senden Sie einen Kommentar:
Kommentare sind ausgeschaltet.