Contents
- Six key areas CIOs must master
- Let’s Get Technical Now
- Tuning the Garbage Collector
- Performance Tuning
- Tuning the Tenured Generation
- Tuning the Younger Generation
- Tuning with UseParallelOldGC
- Tuning with MaxPermSize
- Tuning with -XX: New Ratio
- Improve Web Server Connector
- The Bottom Line on Server Optimization and Performance
- Join the CF Alive revolution
Some people may believe that they have the best web server setup. It might run smoothly now, but what happens when it is fully loaded? Does your server still work at its very best? Probably not. What would it take to have better servers?
“It was Nielsen I think that had a survey some years ago which said after eight seconds, anyone on the webpage would go elsewhere if they had an alternative. Eight seconds doesn’t sound like a long time, but you know I wouldn’t still be doing what I’m doing if there wasn’t a lot of issues going on with performance on web servers and application servers, and it’s not just ColdFusion.”– Mike Brunt, the CF Whisperer
As Mike stated, there are many issues going on with web servers and that includes those of CF. Fortunately, there are some steps we can take to optimize the performance of our ColdFusion web apps and servers. By taking a look at these 4 focus areas, you can make sure your CF servers and apps perform at their very best.
In this article, you will learn:
-
How to configure the JVM
-
How to tune the Garbage Collector
-
Various steps to take for Performance Tuning
-
How to improve your Web Server Connector
Six key areas CIOs must master
Perhaps one of the most enduring goals for you is optimal server uptime and performance. It is a daily challenge that needs to be addressed to make sure that your servers and applications run smoothly every time. There are six key focus areas every CIO should embrace in order to meet this goal.
-
Planning.
- Aggressively enforce maintenance schedules and system configurations and double check the work done. Coordinate your acquisitions and upgrades toward system availability and performance.
-
Do your PMS.
- Preventative maintenance is 100% easier and better than a full system repair. It’s just like changing the oil in your car. Better to do it now, than buy a new engine later.
-
Take advantage of monitoring and management tools.
- These tools were created to make your life easier. Use these to gain proper insight into what is causing your server to lag and track how the downtime is hurting your business’s bottom line.
-
Increase your Security
- This may seem like a no-brainer, but you would be surprised how many servers do not have adequate protection.
-
Use Quality Hardware.
- Remember, cheaper is not always better. Make sure you have hardware that can keep up with your company’s current needs. Along with, make sure your hardware can handle future expansion.
-
Common Sense
- This cannot be stressed enough. Do not waste precious man hours and money trying to make an outdated system work. Use your brain and update.
Optimizing your servers and performance may take some work. But, in the long run, you will be much happier that you did.
Let’s Get Technical Now
Configuring the JVM
JVM stands for Java Virtual Machine. The JVM has been the beating heart of Adobe ColdFusion sinc the MX days (ColdFusion 6). During this time, ColdFusion was optimized for security and portability purposes by being completely rewritten inside a Java Runtime Environment. Java is the very root of ColdFusion. So when it comes to making adjustments, it only makes sense to start at the source. The JVM is built similarly to an onion which layers in which the VM is constructed. At the core lies the Java Application Server or the ColdFusion. This core rests inside the servlet container. This servlet container was previously an Adobe construct known as JRun. Since ColdFusion 10 however, the servlet container is switched to Tomcat. Tomcat has consider advantages over JRun including:
-
Faster Runtimes
-
Faster Startup Time
-
Less Memory Consumed
-
More Improved Support for Java EE Specs
The next layer is the Java Virtual Machine itself. The JVM comprises of the servlet (now Tomcat) and the Java Application Server (ColdFusion). All of which rests firmly in your Operating System. This handy infographic from cfguide.io neatly displays the organization.
JVM
Now that you know how the JVM is organized, you must know some basics on how it operates in order to begin tuning. The first thing to realize is how the JVM uses its allocated memory. It breaks down the memory into segments called generations. There are 3 major generations.
-
Old (Tenured),
-
Young, and
-
Permanent.
Young and Old Generations
Both the Young and Old generations handle your application code. The Permanent generation deals with the classes needed to run the ColdFusion server.
The Young generation is divided into 3 partitions.
-
S0
-
S1
-
Eden Space
Whenever any code in CFML is executed, objects are created and transferred to the Eden Space. During the execution of requests, these objects are moved between the Survivor Spaces (S1 and S0) and the Eden Space. Unused objects remain unmoved. These object –used and unused– are monitored by a specific process. This process is known as the Garbage Collector. The GC attempts to remove these unused objects in order to free up allocated memory. Sometimes, these objects cannot be collected. They then move out of the Young generation and into the Old generation. Most of the time these objects cannot be transferred due to several references to them throughout the app code. Shared scope variables are prime examples of objects that are referenced all through your app’s code. Occasionally some of these objects get stuck inside the Old generation. These objects collect and slowly draw more and more memory from what’s available. This is known as memory leak. Memory leak can have a very negative effect on your servers. Memory leak can cause:
- Slow and Lagging Servers
- Server Crashes
- App Failure
If this server is used for business purposes, an unexpected downing can hurt your bottom line. Needless to say, memory leak can pose a serious threat. So, how to deal with them? There are two major approaches.
- The easy way is to run an automated detection tool such as CF Server monitor to help locate rogue memory processes. The server monitor is great for Enterprise Editions users. But what about Standard users? FusionReactor and its associated plugins can be a viable option.
- Then you have the hard way. If you are experiencing heavy memory leak without any indication from automation, you will have to manually inspect the code. This process requires you to manually enable and disable portions of code at a time. When doing this, you need to observe and take note of your memory usage rates. These rises and drops can give you clues as to where your memory leak may be hiding.
You may need to make changes to the configuration of your JVM. This process is managed through the jvm.config file. Be sure to make an initial backup to this file before making any changes to your JVM. This is very important as it will help you to revert your system back to its previous state. After doing so, open your config file in a word processor. Find the java.args line. This is the entry that controls many of your JVM config functions. This line is one long line of data with options divided by spaces followed by a dash. Remember to always test any changes made on a staged server under simulated load. This should be done both prior to and after code deployment.
Tuning the Garbage Collector
One of the easiest places to begin your optimization and tuning is with the Garbage Collector. It may be as simple as switching between one of four different GC options.
-
Serial Garbage Collector
-
Parallel Garbage Collector
-
Concurrent Mark Sweep (CMS) Garbage Collector
-
G1 Garbage Collector
The default option for ColdFusion is the parallel Garbage Collector. The number one priority of this option is performance. To achieve this, the GC makes minor collections in parallel with each other. This allows for a more effective collection and can collect much more over time. Applications that have medium to large datasets running on multi-processor or multithreaded hardware benefit most from this GC option. However, this option does have a downside. During a garbage collection event, your system may become unresponsive for periods of one second or more.
Some CFML applications recognize response time as more important than overall throughput. The CMS and G1 GC options may be the right choice in this circumstance. These collectors–commonly known as most concurrent collectors– run concurrently with your application. This minimizes pauses at the cost of placing a slight overhead on your applications. In order to switch to one of these GC options, update your java.args by removing the parallel collector and adding one of the mostly concurrent collectors.
The main objective of tuning your JVM via the GC is by balancing your maximum available free heap while minimizing garbage collection events. The ideal maximum available free heap is 30%. The best way to do this is to collect garbage objects while they are still in the Young Generation.
When your application reaches the upper limit of the maximum available free heap (70%), you will begin to see a significant decline in your CF app and server performance. This is because there are many GC cycles running to attempt to clear the heap. Performance will take a nosedive as it pauses the request processing every time a full GC is running.
You can inspect GC via GC logging. The first step is to actual enable GC logging. This uses the following options to jvm.args :
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=3 -XX:GCLogFileSize=10240k -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -verbose:gc -Xloggc:convectiveGC.log
After input, restart your server. You should see that a new file log has been created in either {cf_root}/runtime/bin or {jrun_root}/bin.
Here you can inspect the log using a GC Log Analysis tool such as GcViewer. This tool will give you a graphical interpretation of your GC and its activities. Using this data can allow you to determine whether your GC is operating as you wish.
Performance Tuning
There are many different areas that you can fine tune and adjust to optimize your ColdFusion servers and applications. Let’s take a look at a few.
Tuning the Tenured Generation
JMeter is a wonderful tool that you can also use to analyze your CF projects. It can give you a proper readout on your major and minor collections. Major collections take more time than minor collections which can lead to slow and even crashing servers. Reducing the amount of major collections will increase your throughput. Here are two techniques you can use in order to maximize performance.
-
Increase Xmx
- This gives you more memory to the heap. When you have memory available, you can transfer it to the JVM and increase the size of the heap. This in turn increases the size of the tenured generation causing less frequent major collections.
-
Increase Xms
- This increases the initial size of the heap. If the initial size is too small, the tenured generation will resize itself more frequently. Once again leading to more frequent major collections.
Tuning the Younger Generation
When it comes to performance, the tenured generation takes a much heavier toll than the young generation. However, for peak performance, both generations can be tuned for optimum output.
-
-Xmn
- This parameter helps you to allocate more overall space in the heap for the younger generation. If you have available memory, this area can be increased to allow more space in the heap for the young generation. This will decrease the amount of minor collections that will be performed and give short-lived objects more time to die. If you have limited memory, decreasing this value may be your best bet. It will allow for more room for the tenured generation resulting in fewer major collections.
-
SurvivorRatio
- This allows you to control the size of the survivor spaces located in the young generation. By decreasing the ratio, you will increase the size of the survivor spaces. Larger survivor spaces give more time to short-lived objects to die in the young generation. Applications that have many objects die young can benefit from adjusting this ratio.
-
TargetSurvivorRatio
- Increasing the TargetSurvivorRatio leads to better utilization of survivor space memory.
Tuning with UseParallelOldGC
Prior to Java SE6, young generation collection was done in parallel while major collections (from the Tenured generation) was single thread. Now, with Java SE6, you can perform major collections in parallel. It may actually improve your particular performance by reverting back to the old settings. Enable the feature by adding the option: -XX:+UseParallelOldGC
Tuning with MaxPermSize
The permanent generation is used to store class objects and method objects. For applications using lots of classes, increasing the size of the permanent generation would help throughput enormously.
Tuning with -XX: New Ratio
The new ratio parameter is the ratio of the size of the tenured generation to that of the young. By profiling your application, you can adjust this value accordingly. This will improve performance output.
Improve Web Server Connector
Proper connection and connector tuning is a pivotal part of preparing your CF servers for deployment. With the advent of ColdFusion 2018 came the Performance Monitoring Toolkit (PMT). The PMT makes it 100% easier when it comes to tuning your connector. Within the PMT lies the connector auto tuner function. Real time traffic and load data on the connector will be tracked and displayed. Administrators and developers can now log in and visualize the load on a time series chart for an individual connector.
There are 3 major parameters that the auto-tuner currently supports.
-
Connection Pool Size
- This determines the maximum number of connections that can be produced in the connection pool. The connector will only create a new connection if there are no free connections available in the connector pool. However, connections cannot be made at all if the connection pool limit has been reached.
-
Connection Pool Timeout
- This governs the timeout value in seconds for each idle connection in the pool. This must be in sync with the connectionTimeout attribute of your AJP connector with Tomcat’s server .xml.
-
Max Reuse Connections
When the AJP connector connects with a ColdFusion server, it doesn’t close the connection even after finishing a request. It maintains the connection active, so it may be used for the next request. This is known as persistent connection.
With the auto tuner, you can set thresholds as to when auto-tuning actually begins. When the limits are crossed, auto-tuning begins and the connection pool is increased. This is a handy feature to help you make sure your web server connector maintains operations at peak capacities.
-
Tuning & Troubleshooting ColdFusion Using Native Tools with Mike Brunt
-
The Impact Of Unexpected Load and How To Counter It with Charlie Arehart
The Bottom Line on Server Optimization and Performance
Remember, maintaining server optimization and performance is not a one and done. This takes constant monitoring and preventative maintenance to keep running at peak performance. Take advantage of monitoring and tuning tools to make sure you understand what your problem is and how to fix it.
When was the last time you optimized your servers? How do you maintain your GC and why?
Join the CF Alive revolution
Discover how we can all make CF more alive, modern and secure this year. Join other ColdFusion developers and managers in the CF Alive Inner Circle today.- Get early access to the CF Alive book and videos
- Be part of a new movement for improving CF's perception in the world.
- Contribute to the CF Alive revolution
- Connect with other CF developers and managers
- There is no cost to membership.