ColdFusion Performance
When analyzing ColdFusion's performance, There are several things to keep in mind including JVM (memory) settings, slowness on the database tier, and memory leaks that can be easily avoided.
Contents
JVM Settings
Sizing the Heap
A good set of 64-bit JVM arguments to start with (for controlling memory and garbage collection) are below:java.args=-server -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -XX:+UseCompressedOops -Xms1024m -Xmx1024m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:SurvivorRatio=4 -XX:MaxPermSize=512m -XX:PermSize=512m -XX:+UseParNewGC -Djava.awt.headless=true
Those settings specify a maximum ColdFusion heap of 1 GB (1024 MB), an Eden space of 64 MB, and a non-heap Perm space of 512 MB. If your application needs a bit more memory, you can adjust the "-Xmx" and "-Xms" values as needed. A good rule of thumb though is to set them to the same value as each other to help improve ColdFusion perform better. More info on tuning the JVM can be found in this article, but the recommended JVM settings above are great for most ColdFusion applications: Java Garbage Collection Tuning
NOTE: This section primarily applies to VPS/Dedicated customers only. Our administrators make sure the Heap is properly sized on our shared ColdFusion servers.
Garbage Collection Performance
Because a lot of the JVM's processing time can be spent in garbage collection of memory, it can be helpful to enable Garbage Collection Logging to your server. In order to do so, just add the following arguments to your ColdFusion server's jvm.config file:-verbose:gc -Xloggc:gc-1.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
If you wish to change the name of the log file, just change 'gc-1.log' to the filename you wish. By default, this file will be created in the same folder as your jvm.config file.
Tuning the Database Tier
Add Indexes
Make sure all database fields are indexed properly, adding indexes for any columns used in a WHERE clause.
Tune Your Queries
Be sure to remove any 'SELECT *' statements in the code. Instead, explicitly name each column used in a query. Also, make use of query advisors such as this free utility: https://tools.percona.com/query-advisor
Cache Queries Where Possible
Does your application have queries that could be cached? If so, enable caching on those queries as shown here: Good Developers Practice Safe Query Caching
The main takeaway is that your application should have the cachedwithin attribute for as many queries as possible. Query caching helps reduce the load on the database server and improves page response time noticeably.
To enable this attribute on your queries, just add the cachedwithin attribute along with the length of time you wish to cache the query.
This example will cache a query for 1 hour 15 minutes:<cfquery name="myquery" datasource="mydsn" cachedwithin="#createTimespan(0,1,15,0)#">
Preventing Known Memory 'Leaks'
Specify CFFunction Output Attribute
For any <cffunction> and <cfcomponent> tags, make sure that you have output="false" specified. If for some reason you do need output from the function, be sure to explicitly add the output="true" attribute. There is a bug in CF that leaks memory when the output function is left of function and component declarations.
Use Var Scope for Variables withing CFFunction
Make sure all functions have their variables in the "var" scope, including queries. The varscoper utility here will check your code for any missing var statements in your code: http://varscoper.riaforge.org/ We highly recommend using this on a regular basis for all your sites.
Handle Bots and Spiders Properly
Because bots and spiders can create a lot of useless sessions when indexing sites, we recommend setting a custom session timeout as shown here: Lower Session Timeouts for Bots and Spiders
Debugging Individual Scripts
During non-peak hours for your site, try enabling the ColdFusion debug output and adding your IP to the remote debug IP list. Then load the most frequently accessed pages and grab the debug output. Once you have this, focus on improving the slowest sections of code first.
Additionally, if you have Seefusion on your VPS, it will hightlight the server's slowest scripts. You can also obtain stack traces of running scripts to find the root cause of any slowness.