The Harmonious Programmer - Covering a symphony of technical and sometimes off-topic subjects

Fixing a Mysterious Memory Leak on ColdFusion 8

Last year I noticed a strange problem while developing the Mach-II Dashboard on an Adobe CF8 based application.   If I reloaded my entire Mach-II application through an URL argument which called the bootstrapper loadFramework() method everything was fine.  However, if I reloaded my application via the Dashboard I would see a slow memory leak of 30MB of Java heap space per reload.  Suffice it to say that in normal development, you can reload an application many times every day.  Thus this was very bad.  I do remind you that my application is fairly large (200-250MB of heap space to load up).

The only difference between the two methods of reloading was the bootstrapper method instantiated a Mach-II AppLoader CFC and replaced the current one in the application scope.  The dashboard on the other hand would reload the application by reusing the current AppLoader and calling an method on it.  I was able to replicate the memory leak using the bootstrapper by calling the same method that the Dashboard was using instead instantiating a new AppLoader CFC.

I immediately tried to replicate this memory leak on OpenBD and Railo test beds however I did not observe any memory leaks.  So the problem only existed on CF8 and probably CF7 based on another blog post posted by the great development team at Dave Ramsey.  To be fair, I personally haven't tested on CF9 but have heard reports of this from another Mach-II user.

Basically, it appears that CF8 holds on to a strong reference of some type of object in memory and is never released  from the heap for reuse.  I checked a lot stuff in our code base for accidental circular references or something strange like that, but I was unable to figure out the problem.  I even devised a stripped down application based on the Mach-II skeleton and nothing else. This was attempt #1 where I spent about four hours.  Frustrated, I went to bed.

It took a couple of months of just ignoring the problem for me to release all the frustration that I have had about this issue.  Plus, I was out of ideas even after discussing this Kurt Wiersma and Matt Woodward.  So on attempt #2, I decided that I needed to use some more high powered tools available to me.  So I fired up VisualVM which is bundled with Java 6 these days (before it was separate download).  VisualVM allows you to get detailed information about Java applications that are running in a JVM (local or remote) such as monitoring memory consumption, profile applications and take/display heap or thread dumps.  Since ColdFusion runs on Java, this is perfect tool to figure out the problem.

I'll spare you my frustrations, but about four hours in I was able to see that CF8 was holding on to a strong reference to the MachII.framework.AppLoader component which does have a circular reference to another AppLoader when Mach-II modules are in use.  However, my frustrations were not of what was the problem, but how to fix the issue.  So I Googled and Googled for blog posts and after a while I came upon this post (thanks Dave Ramsey guys - great blog name):

ColdFusion 7 Memory Leak (via Web Monkeys With Laser Beams)

So, what the hell?  If I leave off a "output" attribute on a <cffunction> there could be a memory leak?  That seems like a totally stupid bug.  So I did a code base search of Mach-II for missing "output" attributes on <cffunction> tags.  I knew there were a few because CF doesn't treat the "output" attribute like a true boolean.

1. output="true" - output everything
2. output="false - suppresses all output
3. no output attribute defined-  suppresses all output except if you have something wrapped in a <cfoutput> tag

Option number three is used in a couple of places because it is actually quite usual.  Now, this "feature" of the "output" is not documented, but is known to I guess a more advanced CFML programmers.  So I added in cfoutput="true" for all the places in all the places where we had left off the "output" attribute.  I thought I would worry about whitespace suppression later if this work.  So, restarted my instance of Tomcat and did a few reloads of my application via the Dashboard.  I took a heap space dump before I started to get a baseline and did a few more snapshots after a few reloads to see what was happening.

I think after seeing the first results I yelled some expletive along the lines of Holy Cow!  This small change was like a tourniquet on the memory leak.  It was now down to 6MB memory leak per reload.  So I knew there was something else up.  A quick search of ColdSpring showed a ton of missing "output" attributes on <cffunction> tags.  A RegEx replace of those was quickly performed.

After restarting my Tomcat instance, I repeated my analysis process of heap dumps and reloading of my application.  Viola! The memory leak was gone.  Literally, the JVM would recover all the memory -- down the almost 1kb of heap space after a full GCC was requested (which is why I wrote a "request garbage collection" feature in the Dashboard that night).

Summary: Leaving off the "output" attribute of <cffunction> tags can cause memory leaks in certain situations on CF7 and CF8 (even with CHF 3 installed which supposedly fixes memory leak issues with CFCs and memory scopes).

Solution: Never leaver off the "output" attribute!

Cases in the wild: I'm sure everything had a few of these in their code base.

I can't confirm how CF9 handles this stuff since aren't running that on any of our applications at work, but I suspect the same problem exists.  So if anybody wants check, feel free to comment.

----

Update: March 6, 2010

Because I have been asked this a few times.  The CF8 server I was running my tests against was 8.01 with CHF3 installed.

I have filed a ticket for this issue with Adobe as ColdFusion Bug 82362.

Comments [2]

Mach-II 1.9 Milestone 1 (mach-ii.com)

Mach-II 1.9

Hot on the heels of the Mach-II 1.8 "Simplicity" final release, Team Mach-II is proud to announce the availability of Milestone 1 (M1) of the 1.9 "Integrity" release.

As we've mentioned a few times before, starting with Mach-II 1.9 we are moving to milestone releases in order to get fully completed features in your hands as soon as possible. This helps us better organize and complete the development tasks involved with the release, and our users can help us by testing the new features as they're completed instead of waiting for the full final release, or potentially having numerous partially completed features in nightly builds.

Mach-II 1.9 is code-named "Integrity" because one of the main focal points of this release is adding validation capabilities to the framework. An integral part of validation is internationalization, so i18n is another big piece of Mach-II 1.9. We've made great progress on these features and they'll be available in future milestone releases. You can read about some of our plans for i18n features on the Mach-II wiki.

In keeping with our smaller, faster release cycle, we started with some low-hanging fruit for Mach-II 1.9 M1, including:

  • Boostrapper "loading page" option - #195
  • Add 'prepend' attribute to the view-page command - #420
  • Improvements to the logging package
    • Use for M2 logger output when on Open BD - #439
    • Allow for MachIILogger use IP list to show debugging output - #329
  • Improvements to the HtmlHelperProperty
    • Add support for nested "inline" JS in asset packages - #469
    • Add option to add JS before HTML body in HtmlHelperProperty - #230
  • Miscellaneous improvements
    • Add ability to use a module event as default event - #382
    • Add helper methods to ViewContext and BaseComponent for environment related functionality - #467

Grab the Mach-II 1.9 M1 zip now and help us by starting to incorporate new Mach-II features into your development cycle right when they're available.

As for our plans for future 1.9 milestone releases, we're a completely open book. You can read about all the milestone plans on our roadmap, and please let us know if you have feedback on any of the great features we have planned for 1.9. And we can't wait to start sharing our plans for 2.0.

As always, thanks for your support of Mach-II! Our users and community are what make Mach-II great, so we truly appreciate everything you do for Mach-II.

All I can say is that the entire team is excited. We're already working towards milestone 2. Get it now.

Comments [0]

Was joint custody a mistake? (Salon.com)

When Simon was 3, he used to call the time after the lights were out and before he fell asleep "the talking dark"; it was one of those pitch-perfect childhood phrases coined to describe an experience not found in grown-up parlance. In the talking dark, Simon talked himself to sleep. In the talking dark, bad guys were defeated, weather was commented upon, stuffed ducks waddled into ponds. He also got two of everything that year: two bedrooms, two sets of toys, two different jammie rotations. Dad's house and Mom's house were very separate places in his consciousness, a firewall built between them so thick that once, when he was with his dad and ran into me on the street, he introduced us to each other. "Mommy, this is Daddy. Daddy, Mommy." But he had one talking dark. One consciousness to inhabit and one narrative machine with which to invent stories out of the tracks of his days.

Although I was much older than Simon at the time, I am a child of divorce as well. I too drifted between two households. During that time, I very much felt like I was living two separate but equally important characters in my two families. Still, I existed in my own world between the two and those lines are gradually blurring over the past years. From all of this, I had a good chuckle at the distilling down of Simon's consciousness to the causal "introduction" of his parents on the street described above. The rest of the article is rather funny as well so I encourage you read the whole thing.

Filed under  //   Divorce   Partenting   Social Commentary  

Comments [0]

The Bloom Box (60 Minutes) - Absolutely Fascinating

Cleaner energy? No power grid? This "fuel cell" could make a difference. Only time will tell.

Filed under  //   Energy   Green  

Comments [0]

Why I'm Proud To Be A Dirty GNU Hippy (GoingWare)

By earning my bread through writing software, I made a pact with the Devil. In seventeen years spent working as a software engineer, I have been required to sign a non-disclosure agreement by everyone I have ever worked for. I have never been allowed to write Free Software. All but a tiny bit of the source code I have written in seventeen years of hard labor is now kept a jealously guarded trade secret by those who paid me to write it. Many of those companies are now long out of business, yet I could still be sued or even imprisoned should I release any of the source code I wrote for them.

So true and probably why there are a lot of people trying to figure out how open source can pay the bills. I'd be one of those as I like sharing my work, but if only it would pay my mortgage.

Filed under  //   Linux   Open Source   Software Development   Software Licenses  

Comments [0]

Open CFML Advisory Committee -- Resignation Letter

Since my involvement in the Open CFML Advisory Committee is public knowledge, here is my resignation letter I shared with my colleagues on the committee.

Dear Colleagues,

My personal commitments  and professional endeavors have changed a lot since I joined the committee in May of 2009.  The demands on my time have increased in the past year and it has become increasingly difficult for me to contribute sufficiently to the CFML specification process. After much thought and internal debate, I have decided to tender my resignation from the Open CFML Advisory Committee.  I have enjoyed working with all of you this past year, and I appreciate everything I have learned from the process. I wish everyone the best going forward with creating a CFML specification.

Best,
Peter J. Farrell

 

Filed under  //   CFML  

Comments [0]

Alex Payne — Don't Be A Hero

If you’ve built a system that’s supposed to be reliable, you shouldn’t be up fixing it at four in the morning. You shouldn’t be getting paged at all hours. Sure, you might need to do some occasional planned after-hours maintenance, or some very occasional unplanned-but-process-driven disaster recovery, but you shouldn’t need a hero.

Heroes are damaging to a team because they become a crutch. As soon as you have someone who’s always willing to work at all hours, the motivation from the rest of the team to produce reliable, trouble-free software drops. The hero is a human patch. Sure, you might sit around talking about how reliability is a priority, but in the back of your mind you know that the hero will be there to fix what doesn’t work.

Another great post by Alex Payne. Everybody knows a "code" hero or has been one yourself as one point or another. The problem that Alex points out is that when it happens too often, you are letting your team be mediocre or lazy and you rely on the hero. By now, I hope you have the time to read the whole post.

Filed under  //   Software Development   Teamwork  

Comments [0]

Speaking at cf.Objective() 2010

I've been invited to speak at cf.Objective() 2010.  I am co-track chair for Tools & Integration track on the conference's content advisory board. I've gotten a sneak peek at the line up of sessions and speakers -- this year looks amazing!  This is definitely one CFML conference you do not want to miss.  I'm proud to announce that I will presenting on the following topics.

Speedy Websites Through Better Front-End
We'll be using tools like YSlow and Google Page Speed to diagnose issues in which we can improve the front-end performance of a website.

Open Source Tools for Debugging
The title is pretty self-explanatory, but we'll be looking a variety of tools that can be used for debugging web applications.  Everything from Javascript to HTML to webservices to file systems to Java.

Living in the Cloud: CFML Applications on Google App Engine
I'm co-presenting this with Matt Woodward.  Cloud based computing, while a buzzword these days, is something that very compelling. So come see how cloud computing differs from traditional application development and how it can open up a different world for your applications.

Simplicity, Integrity and Velocity: What's New in Mach-II
I'll be co-presenting this with fellow Team Mach-II members Matt Woodward and Kurt Wiersma.  We'll be looking at the all the features in the almost ready for gold release of Mach-II Simplicity (1.8), what is already there for Mach-II Integrity (1.9) and hopefully a sneak peek at Mach-II Velocity (2.0).

I'll be sharing more on my presentations in the next few weeks, but take the moment to take advantage of the early bird pricing for cf.Objective() ends on January 29th -- so register now!

Filed under  //   Conferences   Google App Engine   Mach-II   Open BlueDragon   Open Source  

Comments [0]

Example of Bad Security - WeTV.com Exception Shows File Paths

Fatal error: Cannot use object of type MDB2_Error as array in /na/na010uspln2/vol2/production/apache-docroots/wetv.com/public/live/gadgets/ScheduleGadget/ScheduleGadgetIMP.php on line 168

My wife randomly surfed over to the WeTV site and it appears to be down at the moment. Above is an example of a bad security practice -- they show file paths on their exception page.

Filed under  //   Security   Software Development  

Comments [0]

Drone Or Phone? (Shot of Jaq Podcast)

Download ogg Download mp3


It is not often you hear the words “iPhone Killer” thrown around the place and taken in any way seriously, but Android has been getting hopes and expectations a-pumping. Jono Bacon and Stuart ‘Aq’ Langridge crack open the story and explore the opportunities and risks that Google face in how the Open Source community see this exciting new mobile system.

An interesting podcast discussion on Droid or iPhone with Jono Bacon and Stuart 'Aq' Landgridge (i.e. J + Aq). I love the part about using the Droid OS on netbooks. It particularly interesting to hear about how Droid is more "open source" in the terms of applications than the closed source iPhone platform.

Filed under  //   Droid   iPhone   Open Source   Software Development  

Comments [0]