Java Web Applications and Tomcat on low memory servers

I was helping out a family member develop a easy to manage gallery and e-commerce site.  To keep costs down and as a bit of a challenge we opted to go for a server with only 128 meg of ram (only £9 a month with a 5 meg sync line). On this we would need to deploy a jvm, tomcat, mysql database, mail server and the usual list of system applications (ssh and so on). If you add on the requirements for some chunky JAI image resizing code things were going to be tight.

The normal setup (debian) would be apache 2 serving on port 80 connected (mod_jk) to tomcat running on the Sun JVM. We would have open ssh  for remote access, mysql as the database and postfix as the mail server.  This doesnt work out of the box, the server was using swap space straight away. Java doesnt work out of swap space.

The first thing to go was the apache webserver, I just told tomcat to listen on port 80. Next we needed to tune the out of the box settings for mysql server, these two lines will save you a reasonable about of ram:

skip-bdb
skip-innodb

So with this setup and setting heapsize to 8 meg and permgen to 30 meg we have a swap freesystem. If we start stressing it (and we are remotely connected with ssh) then the system does start using swap space. However, worse than this, as I opted to use hibernate (for rapid application development), the permanent generation starts filling up (cglib?).

So the Sun JVM was next to be chucked on the scrap heap, BAE (now Oracle) has a JVM that isn’t crippled with a permanent generation space, so we can garbage collect classes no longer in use. You have to pay Oracle for versions of JRockit after the point the bought out the rights from BAE, but you can still get BAE licensed versions for free…. try here:
http://download2.bea.com/pub/jrockit/60/jrockit-R27.5.0-jdk1.6.0_03-linux-ia32.bin

With this installed I no longer have a server crippled with ‘out of perm gen space’ errors. :)

So nearly there, with the last push we can install BusyBox and DropBear to provide a much lighter-weight ssh server and shell environment.

Now we have 5 meg of ram free after we are connected to the server and running the website at its full jai image resizing glory.

Mission accomplished

Tags: , , , ,

Leave a Reply