Thursday, March 18, 2010

Multiple Grails Apps on a single App Server

Background

Historically I've used Glassfish v2 for hosting many of my Java Web Apps. Lately I've been developing in Grails When it comes to deploying these applications on a production server, the memory requirements are a bit higher than simple JSF applications. Once I had deployed a half dozen or so Grails apps to my production server strange things started to occur such as applications suddenly stopping. I eventually tracked these down to Perm Gen, and Heap memory errors. Through this process I learned that I hate Glassfish's log files (or lack there of).

Goals

A dedicated Tomcat 6 server to host my Grails apps.

The "Hardware"

This server will be a multi-core machine with 4GB of RAM. I'm running it as a VMware virtual host, but a physical machine won't be too different.

The Operating System

Start with the Ubuntu Server 9.10 64-bit install ISO
For most of setup, the standard answers apply except where noted.
Because the host is a virtual machine, at the boot loader screen I choose to hit 'F4', and selected "Install a minimal virtual machine" as the setup type.
For disk partitioning, I always use LVM.
When the installer gets to the "Software Selection" screen, enable OpenSSH Server, and Tomcat Java Server

Tomcat Settings

Pay close attention to this section. This is where you need to configure your memory setting appropriately. Most grails applications need at 64 MB of PermGen space each, and somewhere around 64-128MB of

Add the following options to /etc/defaults/tomcat6

# change the default garbage collector
TOMCAT6_SECURITY=no
# Tell the JVM we're "headless"
JAVA_OPTS="-Djava.awt.headless=true"
# Set the Memory Pool Size
JAVA_OPTS="$JAVA_OPTS -Xms2048m -Xmx2048m"
# Set the PermGen Size
JAVA_OPTS="$JAVA_OPTS -XX:PermSize=1024m -XX:MaxPermSize=1024m"
# change the default garbage collector to
# The "recommended" garbage collector for Web Servers
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"

Remote Management


Setup Tomcat Users so you can use the manager app by editing /etc/tomcat6/tomcat-users.xml


<tomcat-users>
<role rolename="admin">
<role rolename="manager">
<user username="yourusername" password="SecretPassword" roles="admin,manager">
</tomcat-users>

No comments: