Sunday, October 24, 2010

Memory Consumption of the Grails Command Tool

Yesterday, I decided to reuse a Virtual Server with 1 GByte RAM as an continuous integration server for my Grails development.
Setting up Tomcat, Hudson and Artifactory was quickly done. To ensure safety, I checked the memory:

root@dev:~# free -m
                 total       used       free     
   Mem:          1024        661        362 

Ok, up to 360 MBytes left. That should be sufficient for the Grails Command Tool.
I installed Grails 1.3.5 and run a grails help. Oops, the following exception was thrown:

.......
Base Directory: /root
Resolving dependencies...
Dependencies resolved in 2084ms.
java.io.IOException: Cannot run program "/usr/bin/env": java.io.IOException: error=12, Cannot allocate memory
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
        at java.lang.Runtime.exec(Runtime.java:593)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.......
       Caused by: java.io.IOException: java.io.IOException: error=12, Cannot allocate memory
        at java.lang.UNIXProcess.(UNIXProcess.java:148)
.........

I was wondering why Grails would need more then 360 MByte for a simple help-command. Looking around I recognized that Grails reserves 512MByte MaxHeap-Memory and another 192MByte for the PermSize per default.
It can be adjusted by setting the GRAILS_OPT environment variable. For me it works by adding the following line to the .bashrc (or /etc/environment if needed globally):

GRAILS_OPTS="-server -Xmx200M -XX:MaxPermSize=128m -Dfile.encoding=UTF-8"

No comments:

Post a Comment

And Feedback? Please post a comment: