October 4, 2016
Understanding various types of memory and tuning in ColdFusion
October 4, 2016
Understanding various types of memory and tuning in ColdFusion
Staff 4 posts
Followers: 0 people

Memory management is the process of recognizing, when allocated objects are no longer needed, deallocating (freeing) the memory used by such objects, and making it available for subsequent allocations. Since ColdFusion is an application server, ColdFusion requires memory management for effective performance improvement.

Sun Java differentiates memory across five generations:

  1. Young Generation: This generation holds objects with a high mortality rate. In ColdFusion, usually this space holds a variable that only exists in one page, for example – variable scope.
  2. Tenured Generation: This generation holds objects that live for a longer duration. For example, in ColdFusion, client and session scope variables.
  3. Permanent Generation: This generation holds all the reflective data of the virtual machine itself, such as class and method objects.
  4. Minor collections: This type of Garbage Collection (GC) occurs in the Young generation. In ColdFusion, minor collection collects unreferenced local scope and variable scope variables
  5. Major collection: This type of GC occurs in tenured generation. In ColdFusion, this collection collects all unreferenced session scope variables.


We can optimize the amount of memory allocated to ColdFusion server, for better performance. Let us discuss some of the parameters, which will help in Memory tuning.

  1. -Xmx – Defines maximum Java heap size.
  2. -Xms – Defines minimum Java heap size.
  3. MaxPermSize / MaxMetaspaceSize: The JDK 8 JVM uses native memory for the representation of class metadata and is called Metaspace. Users with JDK1.7 or lower will see the attribute MaxPermSize, and users with JDK 8 will see the attributes MaxMetaspaceSize.


Garbage Collection

Garbage collection refers to the process of recycling memory that was assigned to objects no longer referenced by a program. Garbage collection can be divided into 2 types:

  • Minor collection: Garbage collection that occurs in the young generation. In ColdFusion, minor collections will collect unreferenced local scope and variable scope variables
  • Major collection: Garbage collection that occurs in tenured generation. In ColdFusion, this will collect all unreferenced session scope variables.


Concurrent Collector

If the sites on your server are primarily lightweight request/response applications where response times are critical, then the concurrent garbage collector is a viable choice for your server. This collector does its best to collect dead objects from memory while applications on the server are still processing data. This adds a small bit of overhead for transactional applications, but it helps applications maintain their response-time SLAs.  To enable concurrent collector You need to add one of the following jvm arguments in jvm argument -XX:+UseConcMarkSweepGC  or -XX:+UseG1GC

For more information on concurrent collector please click here

Parallel Collector

If the applications on your server are memory-intensive and allocate a lot of objects, then the parallel garbage collector is a viable choice for your server. Any application performing image manipulation or creating a lot of objects is a great candidate for the throughput collector. To enable this garbage collector, add the following JVM arguments in the jvm.config: -XX:+UseParallelGC

 For more information on Parallel collector please click here  


Where to make the chnages?

You can make the changes at ColdFusion administrator (Settings >>Java and JVM >> JVM Arguments). 

Alternatively, you can tune memory in jvm.config, located at ColdFusion install directory (cf_root >> instance name >> bin >> jvm.config). 

Note: It’s always recommended to take a backup of jvm.config before making any changes.


Sever Monitor

If you have an Enterprise edition of ColdFusion, you can use Sever Monitor to monitor your server. You need to go to ColdFusion Administrator >> Server Monitor. To Start and Stop Monitoring, profiling, and memory tracking, click the appropriate buttons o of the server monitor.

Let us discuss about the Server Monitor in detail.

  1. Start Monitoring: This feature gathers information about all requests, including active requests, slowest requests, active sessions, cumulative server, etc. The Server Monitor does not gather information for requests that are excluded on the filter settings page.
  2. Start Profiling: It starts tag and function timing information for the slowest request reports, active queries, slowest queries, cached queries, and query cache status. You can view about each request that is slow or consumes a lot of memory. You can use this feature on development server. We do not recommend you to use this feature in a production environment.
  3. Start Memory Tracking: It gathers information about memory consumption, including all memory usage, queries and session that use most memory. You must enable profiling to view query-related reports.


You need to see if there is any effect on non-heap or heap memory at all. What needs to be deduced from the graph is, if the non-heap memory increases then, the perm gen/metaspace value needs to be recalculated. Whereas, if the heap memory increases, then the Xmx needs to changed.

You can also take help from some 3rd party software to monitor your server like GC viewer. You can also use Jconsole.  It is another memory management tool provided within JDK. The usage information is available at https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html.

Follow the same procedure, mentioned above for non-heap or heap memory monitoring and tuning.


2016-11-28 11:21:17
2016-11-28 11:21:17

Just to share some advice – Please use Caution in Production with Profiling and Memory Tracking.

Profiling will likely work in production for applications that do not include any batch processing. For example, iF you have a scheduled task that loops thru 3000 updates to your database – profiling will not be able to keep up and your server will likely become unresponsive. I have seen this happen a few times, and it’s tricky to figure out as you likely turned on Profiling days or weeks earlier. So if you know all your batch like functionality is on another server, Profiling should work for you in prod with little overhead. The times where I have seen Profiling get overworked it has been where 1000’s of database interactions are happening. I have not seen any hard data, but anything over 100 queries I would flag as a starting point.

Memory Tracking should not be used in prod. It is great for dev, test and QA. If you must use it in prod be aware you will likley see a performance impact and depending on the app request load might create an unresponsive server.

Monitoring is fine for production. In fact, if you want your alerts to email you a snapshot you will need monitoring turned on.

2016-10-10 21:22:17
2016-10-10 21:22:17

Excellent article. I have a question thou: i have a developer edition of cf11 and running sqlexpress on my local. I created a data source to the local instance of my local sql db. However, when i tried to add another datasource to connect to the same instance of sql serve just pointing to another database, the add datasource is always coming prepopulated with existing datasource when i press ADD and no matter what i put in there, when i save it it replicates the existing datasource. Any advice here, pls. Regards Art

2016-10-05 05:27:10
2016-10-05 05:27:10


Add Comment