Related Topics: ColdFusion on Ulitzer, Java EE Journal, Java Developer Magazine

CFDJ: Article

CFDJ Cover Story — JVM Tuning

The application, machine, and JVM version make a difference

How to Make the JVM Setting Changes
Changing the Heap size is very easy through the ColdFusion administrator (see Figure 2).

The default settings are shown in Figure 2. There is a strong argument to set the Minimum and Maximum settings to the same size. The reason is that it will keep the JVM from having to calculate this for itself, thereby allowing the JVM to focus on more important things. But when you do this, more attention will need to be given to the JVM to see if any java.lang.OutOfMemoryError errors appear in your exception logs.

How high can you increase the Heap size? This depends on the JVM version and hardware being used. You will need to do some research here. Most recent JVMs on a 32-bit system usually have a limit near 2GB. Sixty-four bit systems can run much higher. If your server has only 2GB of memory, it would be safe to only go up to 1GB for the JVM. Remember, your other applications need memory too.

You can actually lower your server's performance by setting your Heap size too high. If, for example, your JVM never exceeds 100MB of memory, and yet you have the Heap size set to 1024MB, you are asking the garbage collector to manage a bigger memory space than it really needs to. Look at your Tenured space and see how often it fills up. If it rarely seems to fill up, there is no reason to increase your Heap size. If you lower your Heap size, pay attention to your exception logs for java.lang.OutOfMemoryError errors because this will serve as a warning that the JVM is running out of memory.

The Permanent space size can also be controlled. This setting can be found in the JVM arguments section of the CF Admin. In the arguments, you should see something like this, "-XX:MaxPermSize=128m". This argument simply tells the JVM that the maximum allocation of memory for the Permanent space is 128MB. Depending on what your ColdFusion application server is doing, it may be necessary to move this setting up to 192MB or 256MB. If your server is creating a lot of class objects, then it may be necessary to move this limit up.

The garbage collector can also be changed and tuned. The default garbage collector used by ColdFusion 6 and 7 is called the Parallel Young Generation collector (or Parallel Scavenging), which is a part of the family of Throughput collectors. You will need to go directly to the jvm.config file to see its setting. Under the JVM arguments, you should see the following, "-XX:+UseParallelGC". There are actually several others to choose from. The two major families are Low Pause Collectors and Throughput Collectors. The differences are in how they treat the balance between GC pauses versus processor performance. The Low Pause family of collectors will allow applications to run during part of the GC process. It does this by not moving "live" objects when it's removing dead objects from the Tenure space. This, however, costs the collector in performance since it has more complexity to its task. So Low Pause collectors give you smaller GC pauses but with more processor time than with the Parallel collectors. Throughput collectors have longer GC pauses but greater CPU throughput because the application threads are not sharing the processor time with the GC. Typically, applications with large real-time data prefer the Low Pause collectors, but you will need to see if you have the available processor resources to make this type of switch.

In summary, if you feel that the default collector is not very efficient, research the others available and test to see if they can help your system. Note, other JVMs sometimes carry with them other collectors. For example, the JRockit JVM from BEA has the Dynamic Garbage Collector, which is not available with Sun.

Finally, How and When to Optimized the JVM
In most cases, you do not want to see the Tenure space fill up very often because when it does, the JVM has to run a full garbage collection, which takes up time and resources. Plus, you run the risk of the JVM not being able to flush out the memory in time and crashing your ColdFusion server. So adjust your JVM heap size to fit the needs of your system. If you want to switch out the garbage collector, I would advise you to do plenty of research. Sun has a lot of documentation on this subject regarding this, and O'Reilly has an excellent book called Java Performance Tuning by Jack Shirazi. As always, test any setting changes on a development server first before applying to a production environment.

As you can see, the JVM settings are extremely powerful and can do a lot to improve your ColdFusion application performance. My hope is that this article encourages you to learn as much as you can about the JVM and its settings. If you are interested in learning more about this and our research, please visit http://labs.fusionlink.com for more information.

More Stories By John Mason

John Mason works at FusionLink, which specializes in ColdFusion hosting services. He is a Certified Advanced ColdFusion developer and has been working with ColdFusion since version 2.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.