How to Tune the JVM for High Availability Coldfusion Servers: Part 1

You tune your code, you tune your queries (I hope), you may even tune your guitar, but I bet you have never tuned your JVM.  

Why should you?

Your ColdFusion installation does not run directly on your server that's why.  ColdFusion runs in the Java Virtual machine.  Essentially the JVM is a virtual server (ie. the VM part of JVM) and if this virtual machine is not setup properly your ColdFusion installation may not perform as well as it should and may not even run at all. When speaking with key people from Adobe about the JVM I found out the JVM ColdFusion file (jvm.config) is shipped with a known to run basic configuration, but it is by no means ready to run under high demand situations.  For those saying, but 'Shouldn't ColdFusion do that?' or 'Why should I have to tune the JVM?'  The anwser is No, it shouldn't.  And you have to configure the OS of any computer you own in order to get it to run properly the same is true with any VM you may want to use including the JVM.  Remember the old days of DOS when you had to configure your config.sys file to get your brand new 8bit Soundblaster card to work?  Or maybe you've used a Linux distro. In either case you had to edit text configuration files to get everything just right. 

So, what happens when you don't tune the JVM.  You most likely already know and that's why you're reading this blog post. Ask yourself what happens when your business or website becomes successful and your server fails routinely?  You loose business that's what happens. If that isn't incentive enough I don't know what else to tell you.

What are the symptoms of an incorrectly tuned JVM?

They can be anything from slow performance, regular pauses to page processing to random and frequent JVM crashes.  The worst that can happen is your website won't even be able to stay running for a few minutes under load.  Typically I see posts with subjects like 'Help, ColdFusion keeps crashing' or 'My ColdFusion keeps hangimg'.  I'm here to tell you it's not ColdFusion.  It's either the JVM, the DB, network connections or your code.  Today we'll focus on the JVM.

What qualifies me?

I've been there done that.  At my current employer our systems administrator and I spent weeks learning via trial by fire to tune the JVM for super high availability and performance.  Much of what I am about to explain was taught to me by Ryan (our systems administrator) and by our searching the web to learn about the JVM.  Between the two of us we were able to get our single standalone ColdFusion install to easily handle 1.5 million ColdFusion page views a day.  And at peek usage anywhere from 30 to 50 simultaneous requests per second.  Since then we've moved to a cluster of failed over servers with three ColdFusion MX 7 Enterprise servers behind a load balancer.  (*UPDATE* We've upgraded all of those servers to ColdFusion 8.0.1 64Bit Enterprise.)  There are differences in tuning these different setups, but the basics are the same.  If your using ColdFusion 8 you will benefit from the newer JVM that is available.  You should also be aware that Sun has declared the end of life for the JVM 1.4.2 line.  That date was October 30th 2008.  Isn't it time to upgrade to ColdFusion 8?

java.sun.com/j2se/1.4.2/download.html version 1.4

java.sun.com/javase/downloads/index.jsp version 1.6

How do I?

You simply edit the jvm.config file.  Of course you need to know what to edit.  The ColdFusion administrator does have a section that lets you edit the 'JVM Server Settings > Java and JVM'.  This does not let you edit every aspect of the file, plus on Linux servers the admin tool can corrupt the jvm.config file.  So get used to editing the file itself.  On Windows you can use Notepad, on Linux you can use 'vim' (or other lesser text editors).

What to edit?

There are several things to looks at. First you need to be using the correct JVM.  The JVM that ships with ColdFusion 7.xx is outdated and buggy.  Don't blame Adobe, they only ship what Sun made available.  Sun has released several newer JVM versions.  If you are running anything older than JVM 1.4.2_13 you NEED to upgrade.  Everything prior could be unstable under very high load and in some cases minimal load.  If you're runnning ColdFusion 8 and you're not using the newest JVM 1.6_10 or later you're most likely having some issues.  Many people have reverted back to the 1.5_x version due to the Java Class Loader bugs in the earlier versions of 1.6.0.  With the newest update these issues appear to be resolved.  So upgrade to 1.6.0_10 or newer.  java.sun.com/javase/6/webnotes/6u11.html

Download and follow the instructions to install the new JVM.  Do not install the JVM over the one from Adobe, install the new JVM in a new location.  This is done so you can easily switch back to the old JVM if needed. Once installed edit your jvm.config file and change the line that points to the JVM to your new JVM.

On Linux it may look something like this.

view plain print about
1#java.home=/opt/coldfusionmx7/runtime/jre

view plain print about
1java.home=/usr/java/j2re1.4.2_14

Restart ColdFusion, it should run with the same JVM settings.  If ColdFusion won't start you can edit the jvm.config file and undo your changes.  Of course before editing you did save a copy of the original file.  Right?