Running Grails Applications on a VPS (Spencer Uresk)
Grails, Spencer Uresk June 13th, 2008
Spencer Uresk presents some tips for running Grails enabled applications in a VPS (Virtual Private Server). As you know Java based application hosting is not cheap compared to alternatives like PHP or even Rails, which is why many of such applications are hosted and maintained within the same organization that created them. Java friendly VPS offer an option for small to medium sized web applications to be run under a modest budget compared to what you would have to invest if doing it by yourself all alone.
For some time, it has been one of my dreams to see Java-based web applications be more viable for small websites. This means two things: rapid development capabilities (like Ruby on Rails), and inexpensive, reliable, and economical hosting options.
For goal #1, Grails is clearly fitting the bill. I spent the last year or so developing Rails apps, and Grails feels almost as productive. The community around it is getting quite active and there are some excellent plugins.
Reaching Goal #2 is going to be a bit trickier, but I think we are getting close. I am able to deploy 3 or 4 Grails applications on a 256 MB VPS now, and they work reasonably well. The good thing is that VPS’ are getting quite cheap, and a VPS with 256 MB of memory can easily be had for less than $20/month.
Spencer’s tips are
1. Dump Apache HTTP server
A lot of people would use Apache to forward requests to Tomcat. There is nothing wrong with Apache HTTP server itself, but in this setup, it can eat up a bunch of memory and really isn’t necessary. You can use iptables or xinetd to forward requests from port 80 to your app server. Doing this should free up a bit more precious memory for your app server.
2. Make sure you are using the server JVM
This is easy to forget to do - HotSpot will automatically choose which vm to run based on server attributes, so on a real production box, it will choose the server vm automatically. On a VPS, you’ll need to manually do this by adding “-server” to CATALINA_OPTS.
3. Give you server more PermGen space
Groovy uses a bit more PermGen space than normal, due to all the classloading it does. This means you’ll probably want to configure your vm to use a bit more PermGen space than usual by doing -XX:MaxPermSize=m. On my server, setting this to about half of the overall memory allocated seemed to be the best, but your results may vary.
4. Experiment
Ideally, you’d just upload your apps and not worry about tuning, but when you are trying to squeeze the most out of a VPS, this isn’t the case. Play around with different memory settings and other vm options to see what gets your particular setup the best performance and stability.
Tags: Grails, Spencer Uresk
About