Understanding various types of memory and tuning in ColdFusion

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.

 

Migrating CF Admin settings from ColdFusion 9 or 10 to ColdFusion 11

Since we have been getting lot of calls/queries around migration these days, I thought it would make sense to make a blog post on it. Now, since Migration is a very broad subject we need to keep in mind the Technology, Hardware, Operating System, Settings, Application Server, Web Server, Code compatibility.

In this article we will discuss 2 ways on how to migrate CF Admin settings from ColdFusion 9 or 10 to ColdFusion 11.

  1. Migrate via Car files
  2.      Migrate via migration wizard

Migrate via Car files:

ColdFusion archive files (.car) files can be generated and deployed only if both the version of ColdFusion are in enterprise edition. Out of all the differences between standard and enterprise edition, one of them is that you cannot create a .car file in standard edition (but note that generation of car files IS now available in ColdFusion 11 standard edition).

So, if you have ColdFusion 9 (or 10) Enterprise edition and ColdFusion 11 Standard or Enterprise edition you can migrate via these method. If you need to migrate from Coldfusion 9 Standard, see the final section, "Migrate via migration wizard".

To export your CF9 Admin settings (in ColdFusion 9 Enterprise), in the ColdFusion 9 admin page please go to packaging and deployment >> ColdFusion Archives. In the ColdFusion archives page you will find two options

         ·         Deploy an Existing Archive

         ·         Create an Archive

Now, since we are creating the archive file we will select create an archive option. On the Archive name option let us give a name say “test” and click on create. Once the archive is created it will be listed under Current Archive Definition List. In the actions bar please click on the pen icon (refer to the image below):

 

When you click on the icon, a pop up page will open up where you can select all the settings that you want to migrate (refer to the image below)

After you select all the required settings you can click on close window button. After closing the pop up window, let us click on the build archive button (refer to the image below)

 

When we click on that button, a pop up page opens up where it gives you a summary of the selected settings (refer to the image below)

Please select next after you have reviewed the settings. In the next page, we will be asked to select the .car file. Now, let us create a folder in say “C” drive and name it test. Now, inside the folder let us create a file with extension .car . Let us name it migrate.car. Now, in the page let us browse to the that folder and click on okay and add the file name, the path should look like C:/test/migrate.car (refer to the image below)

Now, let us click on next and we should get a popup message saying “Build Successful” (refer to the image below). 

Click on okay and close the window. Now, let us go to ColdFusion 11 admin page and go to the same place that is  packaging and deployment >> ColdFusion Archives. Let us remember that we have already created the .car file and now we need to deploy it. So we will work on the first option that is deploy an existing archive. Click on the bowser server option and browse to the migrate.car file which we have created earlier. (Refer to the image below)

After entering the path click on deploy button and a pop up window will appear. Click on next and the next page will give you the option to deploy and it will specify the Deploy Locations as well (Refer to the image below)

Once you click on the button deploy, you will get a pop up message saying Deploy successful (Refer to the image below)

 

When you get the above message you have deployed the .car file successfully and with it migration from ColdFusion 9 to ColdFusion 11.

 

Migrate via migration wizard

In case you have a ColdFusion 9 (or 10) Standard installation and are moving to ColdFusion 11 on the same server, then you need to modify the adminconfig.xml within ColdFusion. The location for adminconfig.xml is ColdFusion11cfusionlib

Now, if we are trying to migrate from ColdFusion 9 to ColdFusion 11, please follow the below mentioned steps:-

        ·         Navigate to adminconfig.xml for ColdFusion 11 and open it with text editor.

        ·         Change the value from “false” to “true” at

                          <Runsetupwizard>false</runsetupwizard>

                          <Runmigrationwizard>false</runmigrationwizard> and

                          <migratecf9>false</migratecf9>

        ·         Save the file and restart ColdFusion Service.

After restarting the service, you will get the migration wizard. Follow the on-screen instructions to continue.

 

 

Suggested workaround if .Net objects are corrupt or are not working post install

When using .net objects with ColdFusion 11 with cfobjects, it sometimes throws the following error:

 

This following error occurs when .Net framework is not
installed on the server or it is corrupted. We need to install an updated
version of .Net framework matching the bitness of server i.e. if the server is
32 bit you would need to install .Net framework of 32 bit and if the server is
64 bit then you would need to install 64 bit version of .Net framework. If the
.Net framework is installed, try repairing it using the following steps:-

  1. Obtain the original installation source. For example,
    if you installed the .NET Framework from a CD-ROM or from a DVD, insert
    that disc. If you downloaded the .NET Framework , download the .NET
    Framework again. Make sure that you click save to disk. If you
    installed the .NET Framework from a network share, reconnect to that
    share.
  2. Click Start, click Run, type
    the following command, and then click OK:

N:dotnetframeworkdotnetfx.exe /t:c:temp /c:”msiexec.exe /i
c:tempnetfx.msi REINSTALL=ALL ReinstallMODE=vomus”

Note Replace N: in this command syntax with
the original installation path.

Important If you do not have a C:temp folder on your computer,
create one before you run this command.

 

The Microsoft Windows
Installer will verify and repair the .NET Framework installation.

After
repairing it is very important that you restart the server once. Once the
server is restarted and up and running you should be able to run .Net objects
as it should.