Memory leaks with Coldfusion 8

For the past few weeks I’ve been incognito due to some memory leak issues we’ve been having with our new app. It is essentially a rewrite of our existing web application using Object Oriented techniques and embraces the Model-View-Controller paradigm. It really is a pretty little thing but unfortunately she crumbled under the weight of the world wide web. Anyone who has faced the memory leak problem will know that it is not an easy one to crack and it takes time to determine the exact issue. There are a lot of articles around that have excellent information which were all very helpful in my quest for a solution.

The system made a lot of use of the session and application scope for caching objects which was the first issue that we had to overcome. It seemed like a good idea, you’ve got loads of memory, you have a finite amount of objects that can be called for each session why not persist them. The problem is that ColdFusion 8 seems to have an issue with complex objects (i.e. CFCs) stored in the session and application scopes. The reason I say this is that we were seeing a very, very strange thing happening to the memory on our server. When load testing was run, the server was fine, the memory steadily increased until the initial sessions began expiring and then the average of memory usage plateaued, which is what you like to see. However, once the load test ended the memory steadily increased until it crashed the CF instance. Weird right? And so the search for a solution began. I came across a few helpful articles:

http://www.ghidinelli.com/2009/07/16/finding-memory-leaks-coldfusion-jvm

http://www.schierberl.com/cfblog/index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler

http://www.alagad.com/blog/post.cfm/troubleshooting-coldfusion-performance-analysis-part-ii

These were tremendously helpful in assisting me in finding the solution. The last post from Alagad was the one that helped cure my issue in the end. You need to ensure that when making copies of persistent scoped variables that they are deep copied or used in a local scope within CFC functions. However, bear in mind that there are many causes for memory leaks and you should spend the time in figuring out the exact cause of your problem. I found the MAT tool supremely useful.

Here are some tips for curing memory issues:

  1. Install cumulative hotfix 4 for ColdFusion 8.0.1 (Get it here)
  2. Update the JVM to the latest provided by Sun, in my case it was JDK 1.6.0_18 (Get it here)
  3. Add the -XX:+AggressiveHeap option to the JVM configuration (Read about it here)
  4. Set your min and max heap to the same size to reduce the number of garbage collection calls
  5. Run varscoper against your code and ensure all local variables are var scoped (Get it here)
  6. Limit the use of variables scope within objects, use the THIS reference instead
  7. Limit the number of complex objects (cfcs) being stored in SESSION and APPLICATION scopes
  8. Clear the variables scope onRequestEnd (this doesn’t really work when using Application.cfc though)
  9. Run load tests! We used WCAT for Windows (Get it here)
  10. Turn off CF monitoring use FusionReactor (or something similar) (Get FusionReactor here)

Hopefully these will help someone else going forward.

Posted in ColdFusion, General, Programming, Web 2.0 | Tagged , , , | Leave a comment

Apple Tablet? So what’s the end game Steve?

So, there are more than just a few rumors about the possible Apple Tablet and why wouldn’t there be a lot of buzz around the company that has a knack of delivering products that changes paradigms? I personally don’t think there will be one. Now, to be clear, I would very much like there to be one but one question keeps coming up for me. Where will the Apple Tablet fit into the company’s product line? A lot of buzz today seems to think that Amazon’s changing of the Kindle royalty fees to publishers is some indication of the iminent arrival of the iSlate. I can’t seem to connect the dots. How will Apple benefit from developing a tablet that would directly compete with the Kindle? Reading books on the iPhone or iPod touch are just as enjoyable. There is definitely a gap in the market for a tablet device, techies have been after it for years and let’s face it, who would be better to develop one than Apple? However, what is the market segment that this fit into?

Schools – Apple’s devices have never been cheap, hence I don’t see it replacing paper notebooks in the short term.

Business – Executives could walk around with their slick tablets and look ace in the boardroom but other than that, who in the organisation would benefit from a tablet? Assistants? Would the market be big enough? I may be being very short sighted here but are there any others who would benefit?

General Consumers – Why would home users choose a tablet over a laptop or a desktop? I wouldn’t, would you? Why? How will a tablet provide a better user experience?

The iPod and iPhone were part of the master plan for creating the AppStore and iTunes which are the real cash cows for Apple. Apple is happy on the desktop and laptop fronts because if they wanted to compete head to head with Microsoft or Dell they could be churning out low cost machines with the same awesome OS X. Although, they have cornered the design, music production, video production and now developer communities with their hardware. Where will the tablet fit and how will it benefit Apple?

Forget the hardware, what is Apple planning in the long run? This is the question that everyone should be asking. I guess on January 27th 2010 we’ll all find out.

Posted in Apple, Business, Thinking | Tagged , , | Leave a comment

Chivalry, it’s not dead…

Yes ladies, you heard me right, it is not dead, it’s just under cover. Like Jack Bauer infiltrating a Columbian drug cartel, Chivalry has assumed a new identity and trying to fit in or die. Men blame their lack of chivalrous behaviour on women (as we do with most things) and to be honest we are a bit confused with what should be done and what should not be done. I believe that most men would like to open doors, help little old ladies cross the street and help neighbours with their groceries, but, how many times has this backfired on the average man? In today’s world of sexual innuendo it seems that every gesture is framed as a possible attempt to hit on the person on the receiving end of the gesture. Just recently, I saw two ladies moving a table down a flight of stairs. They seemed to be struggling a bit, so I asked (I’ve learned from experience that you just don’t rush in to help anymore!), “Would you like some help?”. To which the response was, “I don’t need a man to do anything!”. Now, it was clearly said as a joke but with undertones of determination. Like most things in life, men aren’t necessary to women, but we are nice to have . The statement really took me by surprise. It’s not that I was being macho, but more that I was genuinely willing to help, if it were two men doing the same job I would ask the same question. To be clear, there are jerks out there, men who have no regard for anyone in the rush of getting through their day. However, there are some diamonds in the rough.

So today ladies, take a step back, look around you and see the hints of days gone by where men still do the little knightly things that make us nice to have around……sometimes.

Posted in General, Random, Talking | Tagged , , , | Leave a comment

Communication tip

Communication is essential in life, so my tip for today when sending a message is to think of it as a text message (but using proper grammar!). You only have a limited amount of characters to use, so use them wisely and reduce the fluff. This can be applied to both verbal and written messages.

This is the end of this post. :)

Posted in Thinking | Tagged | Leave a comment

JSON format and serializing ColdFusion query objects

Every so often there is a tiny problem that has you scratching your head until you RTFM. I love JSON, it’s totally awesome and the fact that you can not convert CF objects natively is even better! I ran into a small issue where I was using serializeJSON on a structure that contained a query object (don’t ask!). The problem was when the serialized string was deserialized using deserializeJSON the query was no longer a query, it was not a structure! It turns out that the serializeJSON function takes two parameters!

SerializeJSON(var[, serializeQueryByColumns])

The second optional parameter serializeQueryByColumns tells CF to handle queries in a special way. Now the trick is to remember to use the second parameter of the DeserializeJSON function which performs the reverse operation. The second parameter must be set to false for the query object to be recreated during deserialization.

Here are links to the serializeJSON and deserializeJSON in LiveDocs.

Posted in ColdFusion, Programming, Thinking | Tagged , , | Leave a comment
  • Subscribe to my feed Subscriber via Email Follow Me on Twitter! Check me out on Facebook! Check me out on LinkedIn!