Introduction
Achieving highest possible performance and scalability with ColdFusion MX applications is a complex combination of many different factors. Standard performance tuning guidelines in conjunction with the tips provided below should allow you to achieve maximum application performance and scalability. When referring to performance, we're specifically talking about response time of requests to CFML web pages and CFCs. When referring to scalability, we're talking about how those performance results change as you add load to the server. Throughput (number of requests serviced over a given period of time) is also useful in measuring performance and scalability.
Factors Affecting Performance
- Hardware and software configuration
- Database and other external system response time, i.e. database queries, web service consumption, LDAP server queries, and so forth
- Web server performance
- CFML application
The tips in this article will solely focus on hardware and software configuration and CFML application code. As you can see, this is only half the battle. External systems such as databases and web servers require their own tuning and are beyond the scope of what will be covered here. Their importance should be underscored, however.
Hardware
Hard disks, CPU, RAM, and network are the top four factors affecting hardware performance. Investing in the fastest hard disks and CPUs, stocking an appropriate level of memory, and ensuring that network throughput is not a bottleneck are all vitally important to achieving peak performance. If you are new to ColdFusion MX but are familiar with older versions of ColdFusion, you will find that ColdFusion MX has a substantially higher memory footprint. This should be considered when choosing system hardware. Hardware clustering is an option to consider and is well supported within ColdFusion MX architected solutions. See Related Documents below.
Software Settings
Operating System
Tuning software settings starts with the operating system. Each specific operating system has its own specific steps needed to optimize it. See the Related Documents and For Your Bookshelf sections for details on OS tuning.
Java Virtual Machine (JVM)
Since ColdFusion MX is an Enterprise Java Application, the Java Virtual Machine is the software component that is most fundamental to performance. All of the major Java Virtual Machine vendors are constantly investing in research and development for their respective product offerings. Over the past few years this has resulted in significant performance improvements for Java applications. Different Java Virtual Machines from different vendors and different versions of the same Java Virtual Machine from the same vendor all have different performance characteristics. You may find benefit in changing the Java Virtual Machine that you are using with ColdFusion MX.
ColdFusion MX Professional and Enterprise ship with an embedded version of Macromedia JRun 4 as the application server and the Sun 1.3.1_03 version of the Java Virtual Machine. ColdFusion MX for J2EE running on IBM WebSphere Application Server will use whatever JVM WebSphere is configured to use. This will vary depending which version of WebSphere you are running and which fixpak level you have applied. You may find significant benefit by updating or switching the JVM you are using. For instance, applying Fixpak 3 or higher to IBM WebSphere Application Server also updates the IBM 1.3.0 JVM that ships with WebSphere to the 1.3.1 level and significantly boosts performance.
The IBM 1.3.1 JVM is significantly faster than Sun's 1.3.1_03 JVM that ships with ColdFusion MX Professional and Enterprise. Sun's 1.4.1 JVM also has performance enhancements over the Sun 1.3.1 JVM. If you are licensed to use these JVMs (or any other 1.3.1 or higher JVM), you can configure ColdFusion MX Professional or Enterprise to use them by editing thecf_root/runtime/lib/jvm.config file with a text editor and modifying the value of java.home to point at the root directory of the JVM you want to use. For example if you're running Windows and you wanted to switch ColdFusion MX Enterprise Edition to use the Sun 1.4.1_01 JVM, you would open c:\cfusionmx\runtime\bin\jvm.config with notepad and modify java .home=C:/CFusionMX/runtime/ jre to be java .home=c:/j2sdk1.4.1_01. Note: This task can also be accomplished in the ColdFusion Administrator on the "Java and JVM Settings" page.
Caution should be used when switching the JVM, however, as the scope of this change to the software environment is fairly significant. If you decide to change your JVM, do so first in a development or testing environment and fully test your ColdFusion application. It should also be noted that ColdFusion Product Support only provides assistance to ColdFusion MX Professional and Enterprise Edition customers who are using the Sun 1.3.1_03 JVM (J2EE Edition customers are not limited). If you experience a problem that requires Product Support assistance, you may be required to roll back to the original JVM and reproduce the problem so that the JVM can be ruled out as a variable that would contribute to the problem.
Memory
Memory management is performed by the Java Virtual Machine and can have significant impact on your performance depending on how you configure the JVM. The most important settings for the JVM are the "initial heap size" and "maximum heap size." These settings represent the amount of memory that the JVM will use on startup and the limit on the amount of memory that the JVM can use respectively. These settings can be modified for ColdFusion MX Professional or Enterprise from the ColdFusion Administrator "Java and JVM Settings" page using the values for the "Initial Memory Size" and "Maximum Memory Size" settings. The JVM arguments for initial heap size and maximum heap size are -XmsNm and-XmxNm respectively, where N is the size of the heap in megabytes. These JVM arguments are stored in the jvm.config file described above in the value of the java.args setting.
The default maximum heap size is set to 512MB for ColdFusion MX Professional and Enterprise. For best performance, it's best to set your initial heap size and your maximum heap size to the same value. Finding the optimal size for the heap will definitely result in better performance. Setting the value too high can result in poorer performance from the higher degree of garbage collection and internal memory management required for the larger heap.
Setting the heap size too small can result in a java.lang.OutOfMemoryError if your application tries to use more memory than is available to it. The best way to find the optimal heap size is to run your application under simulated peak load with a large heap and monitor how much memory your application actually uses. If you find that your application is only using 180 MB of memory, you might see performance benefit from reducing your heap size to 256MB. It should be noted that java.lang.OutOfMemoryError can pop up in other, more complicated, conditions as well. One common cause of the error is when objects fill up the heap'sPermanent Generation, which defaults to 64MB. It can be increased, for example, to 128MB, by adding the following JVM argument: -XX:MaxPermSize=128m.
Physical hardware memory is an important consideration when finding the optimal heap size. Setting the max heap size to a value that exceeds the amount of free physical memory on the machine is not a good idea and will cause severe performance degradation. For instance, if you only have 512 MB of physical memory on a machine, 512 MB is not a suitable max heap size. The operating system and other running applications all use memory and much less than 512 MB will be available for the JVM process. This underscores the importance of having hardware that meets the requirements of your software application. For best results, run on server hardware with 1GB or more of physical memory.
See Related Documents for a more technical discussion on this topic offered by Sun Microsystems.
Application Server Settings
ColdFusion MX for J2EE relies on a J2EE Application Server such as Macromedia JRun, IBM WebSphere, or BEA WebLogic for the J2EE Engine and Java Virtual Machine. It is important to tune the Application Server settings for performance after deploying ColdFusion and your CFML or Java application. Consult your Application Server vendor for more details on this process. See the Related Documents for IBM's version of this information. For JRun, see the tips in the next section.
ColdFusion MX / JRun Settings
- Simultaneous Requests. The simultaneous requests setting on the "Settings" page of the ColdFusion Administrator has the largest impact on the scalability characteristic of an application (performance under load). This setting dictates how many threads will be used to simultaneously process incoming requests. For most applications, a good starting point for the optimal value for this setting is 3 per processor--a dual processor machine could be set to 6 simultaneous requests. The only way to find the optimal value for this setting is to test your application under load with different values until you find which one provides the best performance under load.
- Trusted Cache. The trusted cache setting on the "Caching" page of the ColdFusion Administrator can be turned on for production applications and indicates that the server will not check the filesystem to see if the CFML source code has changed since it was last compiled. This setting provides the obvious benefit of minimalizing system I/O which has a major impact on performance.
- Updater. Macromedia provides updates to released ColdFusion MX products through cumulative patches called Updaters. Applying the latest Updater will result in performance improvements.
- Debugging. On the "Debugging Settings" page of the ColdFusion Administrator, production applications should have debugging disabled. In some cases, servers are configured to have debugging enabled but limited to specific IP Addresses. Although this configuration is useful in a development environment, it should be avoided in production environments for optimal performance.
- Client Variables. Client variable storage should be configured to use Cookies or an RDBMS for best performance when using client variables. This is done on the "Client Variables" page of the ColdFusion Administrator.
ColdFusion Application
The list of tips in this section is by no means meant to be exhaustive. Below are some easy changes that can be done to your code to improve performance.
Wherever possible, it is best to fully scope your variable names, especially when using the isdefined () function. For example, will perform much better than .
Caching should be used wherever possible in your application. The cfcache tag is available as one mechanism. Database query caching can also provide significant performance and scalability improvements. Database caching is accomplished with the cachedwithin and cachedafter attributes of database tags that support them, such as cfquery . Caching can also be accomplished by storing data in persistent scopes such as session, making it available for longer than a single request.
Wherever possible, it's best to allow database servers to handle data manipulation. Adding SQL code to handle this work will be much more efficient than doing string manipulations or doing in-memory queries (query of queries). Additionally, stored procedures generally provide a higher level of performance than regular SQL queries. Converting queries in cfquery calls to stored procedures and using cfstoredproc is typically well worth it.
There is no substitute for good application design and architecture. Without it, even if you can get the performance of your application within acceptable range, it will be much more unlikely that you will see good scalability.
Load Testing
It would be remiss not to mention the importance of load testing your application. Load testing is critical to the web development and deployment process. Load testing is the only useful tool for tuning and finding bottlenecks. Additionally, load testing answers capacity questions which are essential to have answers to prior to going live with a web site . Load testing should be considered an essential task to perform prior to the deployment of an application. There are several excellent commercial software products available for load testing. Additionally, there are some freeware load testing products that might be sufficient for your testing purposes.
Freeware Load Testing Software
- Windows platform-specific performance settings
- UNIX platform-specific performance settings
- Clustering Macromedia ColdFusion MX for IBM WebSphere Application Server
- Improving Java Application Performance and Scalability by Reducing Garbage Collection Times and Sizing Memory
- Improving Java Application Performance and Scalability by Reducing Garbage Collection Times and Sizing Memory Using JDK 1.4.1
- Java HotSpot VM Options
For Your Bookshelf
Macromedia personnel have found some of the following books useful. These books are not published by Macromedia or Macromedia Press, however, and their listing here does not constitute an official endorsement.
- Java Performance Tuning (O'Reilly)
- System Performance Tuning (O'Reilly)
- Windows 2000 Performance Guide (O'Reilly)
- Sun Performance and Tuning: Java and Internet (Prentice Hall)
- Windows NT Performance Monitoring, Benchmarking, and Tuning (New Riders)
- Windows NT Applications: Measuring and Optimizing Performance (Macmillan Technical Publishing)
- Red Hat Linux Security and Optimization (RedHat Press)