To find bottlenecks in your application during development:
Turn on monitoring, profiling and memory tracking.
Turn the Slowest Request and Requests By Memory Usage report thresholds to zero.
Run your templates.
For each request find:
The slowest tags and functions in the Slowest Requests report.
The largest variables from the Requests By Memory Usage report.
Factors that influence performance include:
Because ColdFusion is an Enterprise Java Application, the Java Virtual Machine is the software component that most influences performance. Different Java Virtual Machines from different vendors and different versions of the same Java Virtual Machine from the same vendor have different performance characteristics. You may benefit from changing the Java Virtual Machine that you are using with ColdFusion.
ColdFusion contains an embedded version of JRun 4 as the application server and the Sun 1.5 version of the Java Virtual Machine. By contrast, ColdFusion for J2EE running on IBM WebSphere Application Server uses the JVM that WebSphere is configured to use. You may find significant benefit by updating or switching the JVM you are using.
To configure the ColdFusion to use a different JVM, edit the cf_root/runtime/lib/jvm.config file with a text editor by modifying the value of java.home to point to the root directory of the JVM you want to use. Alternatively, you can switch to a different JVM in the ColdFusion Administrator on the Java and JVM Settings page.
Because switching the JVM changes the software environment significantly, you should first do so in a development or testing environment and fully test your ColdFusion applications before making the change on a production server.
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. The initial heap size represents the amount of memory that the JVM use on startup; the maximum heap size represents the amount of memory that the JVM can use. You can modify these settings in the ColdFusion Administrator on the Java and JVM Settings page. The Initial Memory Size setting specifies the initial heap size; the Maximum Memory Size setting specifies the maximum heap size. 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, in the value of the java.args setting.
The default maximum heap size is set to 512MB in ColdFusion. For best performance, set the initial heap size and the maximum heap size to the same value. Determining the optimal size for the heap to run the applications on your ColdFusion server results in improved performance. Setting the value too high can result in poorer performance because of the higher degree of garbage collection and internal memory management required for the larger heap. Conversely, setting the heap size too small can result in a java.lang.OutOfMemoryError error 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 uses only 180 MB of memory, for example, you might see performance benefit from reducing your heap size to 256MB.
The java.lang.OutOfMemoryError error can occur in other, more complicated, conditions. One common cause of the error is objects filling up the heap's permanent generation, which defaults to 64MB in size. You can increase the value, for example, to 128MB, by adding the following JVM argument to the Java and JVM Settings page of the ColdFusion Administrator:
-XX:MaxPermSize=128m.
Physical hardware memory is an important consideration when determining the optimal heap size. Setting the maximum heap size to a value that exceeds the amount of free physical memory causes severe performance degradation. For example, if you have only 512 MB of physical memory, you should not set the maximum heap size to 512 MB. Because the operating system and other running applications use memory, much less than 512 MB of memory is 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.
The Server Monitor Summary page monitors the JVM’s memory usage. Use this information when determining the optimal heap size.
You should configure client variable storage 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.
Wherever possible, it is best to fully scope your variable names, especially when using the isdefined() function. For example, <cfif isdefined("variables.myvariable")> performs much better than <cfif isdefined("myvariable")>.
To monitor the memory usage by variables, view the reports in the Memory Usage section of the Server Monitor.
The Simultaneous Requests setting on the Settings page of the ColdFusion Administrator has the largest impact on how well an application performans under load. This setting dictates how many threads are used to simultaneously process incoming requests. For most applications, a good starting point for the optimal value for this setting is 3 per processor; you can set a dual processor machine to 6 simultaneous requests. To find the optimal value for this setting, test your application under load with different values until you find the one that provides the best performance under load. While testing your application, you can view the average response time on the Server Monitor Summary page and the reports in the Request Statistics section.
You can turn on the trusted cache setting on the Caching page of the ColdFusion Administrator for production applications so that the server does not check the file system to see if the CFML source code has changed since it was last compiled. This setting provides the benefit of minimalizing system I/O, which has a major impact on performance. You should set the template cache size on the Caching page of the ColdFusion Administrator to be roughly equal to the number ColdFusion templates that are normally used. To monitor how your settings affect performance, use the Template Cache Status page in the Request Statistics section of the Server Monitor.
In addition, you should use caching 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 the cfquery tag. You can also accomplish caching 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 is 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 the cfstoredproc tag typically improves performance. View database response time information in the Database section of the Server Monitor.