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.
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:
- 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.
- Tenured Generation: This generation holds objects that live for a longer duration. For example, in ColdFusion, client and session scope variables.
- Permanent Generation: This generation holds all the reflective data of the virtual machine itself, such as class and method objects.
- 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
- 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.
- -Xmx – Defines maximum Java heap size.
- -Xms – Defines minimum Java heap size.
- 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.
- 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.
- 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.
- 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.
Hi, i have a problem with Coldfusion 2021. Every night when a Major GC happens, the heap size climbs and I get a 503 error plus an OutOfMemory Error. essentially the application server has crashed, service is still running, but no pages serving. I use Client management and client cookies in my application on my company website, it is the only website hosted on the company server. I get a good bit of traffic, According to this article: ”
- Major collection: This type of GC occurs in tenured generation. In ColdFusion, this collection collects all unreferenced session scope variables.”
So when Major collection is cleaning out the client variables in memory on the server side, and at night after running all day the coldfusion application server just stops serving pages. I dont really want to rewrite all my code to eliminate client variables. Is there a way to remove the reference to these client variables so that Major GC can remove them with out a memory issue? I have fiddled with heapsize and even though i increase memory for the heap the application crashs around midnight when the Major GC happens.
any suggestions? the server stalls every night. thank you.
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.
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
You must be logged in to post a comment.