Nov 30 2008

Good Practices For Scaling ColdFusion Applications

Posted by Mike Brunt at 10:00 PM ColdFusion | JRun-J2EE

These last few days I have been thinking that of all the places in the incredible line-up of Adobe products that my place, in The Heart Of The Matter, the JVM, must appear to be so mind numbingly boring. I mean, good grief, ColdFusion, Photoshop, Dreamweaver, Fireworks, Flash, Flex, AIR, PDF's, Centaur etc etc. Well, I actually find where I work to be very exciting and very rewarding; I know I should get a life!.  Hang on though, we are gravitating from 32-bit to 64-bit architecture which is very significant and critical because, since the advent of web applications, application memory management has been a constant challenge.

Even more basic than that, much of what we all do will end up being served to clients via something.  It could be via printed media, it could be via audio or video; nevertheless, somewhere in that mix there will probably be a server component. In the case of printed media the server may not be so obvious to the reader.  Spare a thought then for that server which will somewhere at sometime be impacted by the creativity we are producing. The web world is unique in the annals of computing, in my opinion.  The rapid processing of requests and responses (threads) is the most important and basic need in web applications.  The greatest cause of problems is threads which are not released quickly and memory leaks; the former can sometimes cause the latter but not always.  Not always because the way that current JVM's work, in terms of memory management, is via a process called garbage-collection. The memory space of the Sun JVM is divided into three basic areas; new generation aka young, old generation aka tenured and permanent generation.  At a basic level, the young generation is where all new objects o when first created, the old is where they go after being around for a while and not collected by the garbage collector and the permanent generation is where the class files for JRun-ColdFusion live. What I typically observe, via verbose garbage collection logging, is that the default settings for all JVM's is inadequate to support ColdFusion and Java (jsp) web applications.  The default maximum heap size, young and permanent heap sizes are almost always not big enough. If you are still interested, please read on.

At the simplest level, objects which reside in memory are inspected by the garbage collector every "x" time-slice (decided by the default behavior of the collector).  They are inspected to see if the application still needs them; if there is still a "reference-pointer" to them from the application.  If there is, they are not collected and are left in the young generation.  One other thing I have observed is that collection from the young generation is more efficient than collection from the old generation.  After around 40-45 attempts to collect the object from the young generation it is moved into the old generation. The ongoing garbage collections are brief and take milliseconds; however, Full Garbage collections can take seconds and that is significant because a Full GC is typically a "stop-the-world" event.  This means nothing else happens on the server whilst a Full GC is underway.  We only want a Full GC to occur as and when necessary and we want that to be as infrequently as possible and to be as short as possible, in duration.  How we code will have an impact on this garbage collectioncycle.  The math is simplistic, the more objects the more memory is needed, the longer they hang around, the more memory is needed.  

Threads play their part because we have a finite number of threads. In a default ColdFusion 8 installation we have a maximum active thread ceiling of 25; this should be more than adequate.  However, if we write our code so that a process can take a long time, we can hang up threads.  When we run out of threads application performance will slow-down and the answer is almost never to dedicate more active threads, the answer is to find out why threads are hanging around.

All objects created reside in memory for some period of time, in ColdFusion, three scopes are worthy of particular note; Request, Session and Server.  The Request scope persists objects for the length of a single request and is typically benign and efficient.  The Session scope pertains to a single users session and dies either when a users session ends (via a log off the session) or when the session times-out as set either in the ColdFusion administrator or in the application code.  The Application scope pertains to a single users session and dies either when a users session ends (via a log off the session) or when the application times-out as set either in the ColdFusion administrator or in the application code.  The Server scope lasts from when the scope-variables are created to when the server is next stopped and started.  Another important point relating to these scopes; the Request scope is available only to that single request and objects residing there should be available to be garbage collected after the request completes.  The Session scope relates to everything that a single user does, the Application scope is available to all users in an application, in my experience, objects in these scopes do not die until the timeout as set in either the ColdFusion administrator or the application code, is reached.  The Server scope is there and available to all applications and all users until there is a ColdFusion or physical server restart.  The Application, Session and Server scopes will all have references to them from the application, the garbage collector will not collect them the first time around and they are most likely to be the cause of memory leaks if there are memory leaks.

To bring this all together, here are my broad brush recommendations for creating efficient ColdFusion applications, as we code, this is based on 9 years of troubleshooting ColdFusion and JRun applications.

Take great care when using Application, Session and Server scope variables.  Create them in as few places as possible and at as high a level as possible in the application.  Use the Client and Request scopes, where possible. If you are using a memory resident "framework" ModelGlue-mach-ii-FuseBox-ColdBox-ColdSpring-Reactor-Transfer or a home grown framework residing in the Application scope, take care to make sure they are efficiently used and bear in mind that you will need more JVM heap memory as that is where they will live. If you are using a community supported construct such as ModelGlue, ColdSpring etc, it is not a good idea to make changes to the core.  Take care with locking the Application, Session and Server scopes, my recommendation is lock only variables creates-writes and used a named lock instead of scoped locks.  Do not lock reads, that is not necessary and can slow down application performance. Avoid copying scopes to another scope, for instance, I have often seen Application and Session scope variables "copied" to the Request scope.  My opinion is thatthis is not good practice and is not necessary.  This was typically done to avoid the need to lock shared scope variables and in CFMX 6.1, CFMX 7.x and CF8, the locking of shared scope variable reads is no longer necessary.

Look carefully at all code that calls out to a dependency such as a Database, LDAP server, Media server, shared file storage etc.  Avoid code constructs such as loops in these cases.  We need all threads to process as quickly and efficiently as possible, as noted above.  Fix all bugs before moving code to production.  If you need a formal error collection mechanism, perhaps something is amiss; yes I know this is a somewhat controversial point of view.

Without fail and I mean that literally, without fail; load test all code before it gets to production and fix any problems revealed by the load testing, this s the most critical part of all.

Comments

David McGuigan

David McGuigan wrote on 04/28/11 10:55 AM

Any ideas on where to start to load test a CF 9 Standard / MySQL / Apache web app? I've been having an issue where a handful of times per day all sites ( though some *seem* to respond a bit faster than others during the freeze ) freeze up for a few minutes and then reconvene with original performance. During this time MySQL seems to still be responsive from a db IDE, but web pages are not.

Our server has gallons of RAM and CF has 10GB for both the min and max JVM heap size.
Thanks.
optimizare web site

optimizare web site wrote on 05/18/11 7:52 AM

The Cold Fusion technology can be used for the website optimization too. A fast website will be better viewed by search engines. I've performed some tests with that and it works well.
superdry uk

superdry uk wrote on 11/18/11 6:14 PM

Every superdry sale fans convinced superdry will be next huge designer. The colors of superdry uk are just amazing because they are universally flattering! It is a great alternative for people who are tired of buying out the entire superdry outlet line and are finished shopping at Our Superdry uk sale store.
resume services

resume services wrote on 12/13/11 10:37 AM

I'm developing a new online resume/applicant software package for my company with Coldfusion. I'm running into a problem because I can't seem to lock the core framework so changes can't be made. I tried locking the scope locks as was suggested, but then I can't seem to add variables. I know this is an easy fix, any suggestions would be great. Thanks
top ccna salary rates

top ccna salary rates wrote on 12/22/11 2:20 PM

Networking is the best option for utilizing coldfusion related items.
marirea penisului

marirea penisului wrote on 03/10/12 4:27 AM

I definitely enjoyed. Go along such way.I delighted to read such post.I liked the way you presented your information.
registro dominios

registro dominios wrote on 03/10/12 12:28 PM

Thanks, that was one of the best sharing. I bookmarked, this article made my day. Keep up your work
TN Pas Cher

TN Pas Cher wrote on 04/08/12 6:50 PM

was one of the best sharing. I bookmarked, this article made my day. Keep
land counselor

land counselor wrote on 06/18/13 12:46 AM

I really like the content of your blog. Seems like you spent considerable amount of time over the most recent posting as well. Well, I must say it has come out really well. Kudos to your brilliant concept.
tape hair

tape hair wrote on 06/27/13 9:23 PM

Appreciate your sharing.
cristiano ronaldo mercurial

cristiano ronaldo mercurial wrote on 11/20/13 9:54 AM

i will keep reading.Please continue to write more good blog Thank you.
typing tips

typing tips wrote on 01/03/14 9:43 PM

This courier is mere conducive for the persons in smart about the famous tournaments. It is a finest of total the experience in conscious about the various scum episodes.
outletshoppingguru

outletshoppingguru wrote on 03/07/14 5:15 AM

Now you can play music with your own hand that will give you real feelings to enjoy the music. Take a visit of all these items and select the best one for yourself.
homesecuritysoftware

homesecuritysoftware wrote on 03/07/14 5:15 AM

Home protection systems the same as CCTV along with other monitoring techniques are certainly essential.
infinityauto

infinityauto wrote on 03/07/14 5:15 AM

They are able to similarly assist you to along with precautionary maintenance so that your automobile will not deal with problems afterwards since the expectation is actually dependably better than remedy.
masculine shopping

masculine shopping wrote on 03/27/14 5:56 AM

A poor reaction doesn’t suggest that your pet and clothing are incompatible, but it will mean you may want to reconsider the precise choice associated with clothes chosen.
my career jobs online

my career jobs online wrote on 03/27/14 5:57 AM

Most companies, however, don’t offer compensated leave with regard to TES work employees. These advantages include health care insurance, life insurance as well as tax preserving programs which are for sale to other workers.
condo law

condo law wrote on 05/08/14 4:35 AM

Really great post. I as of late uncovered your weblog and longed to say that I have truly gotten a charge out of surfing around your online journal passages.
ez work at home

ez work at home wrote on 05/08/14 4:36 AM

Rattling brilliant arrange and style and extraordinary theme, scarcely anything else we require : D.
family law associates

family law associates wrote on 05/08/14 4:36 AM

Abundantly acknowledged enthusiastic about giving such an amenable thought, post is phenomenal, thats why i have examined it completely...
frank xu law

frank xu law wrote on 05/08/14 4:37 AM

These are genuinely monster contemplations in about blogging. You have touched some incredible centers here. Any way keep up writing....
get a lift home

get a lift home wrote on 05/08/14 4:38 AM

Impossibly powerful post, I totally altogether appreciate this site, continue with it.
xihcang

xihcang wrote on 05/20/14 11:17 AM

In the course of every Main competition or even opposition http://www.chaussurefootronaldo.com such as the Entire world Pot, individuals are unable to support yet put on their own spikes http://www.lionelmessif50.com
together with entire satisfaction along with eagerness. The particular shoes http://www.chaussuresfootacc.com that will Nike manufacturer generates spring from an intensive investigation.
xuehua

xuehua wrote on 05/20/14 11:19 AM

They may be set up in boot styles to provide better hold http://www.chaussurefootballpaschere.com
throughout materials the place that the players enjoy. It's important http://www.nouveaufootball.comwith regard to basketball shoes to have this specific component to be able to avoid these people through falling or perhaps getting back in mishaps.
Dr. Thomas Nabors

Dr. Thomas Nabors wrote on 08/21/14 1:38 AM

Practices depends on what they believe in. It should also be approved by the majority.
sparxx rx

sparxx rx wrote on 10/16/14 8:56 AM

Our store sells everything from a weekend supply to a 12 month supply so you can get a proven product at a price you can afford, for as long as you need.
jesiaonk

jesiaonk wrote on 10/30/14 10:04 PM

The you have is very useful. The sites you have referred was good.I am sure that what you have said will definitely pierce the ears of your readers
www.woodstockhealth.net

www.woodstockhealth.net wrote on 11/02/14 12:53 AM

Nothing could be as lucrative than to trade in penny stocks over the counter or OTC for short. To begin with they are priced ridiculously very low costing just few cents or pennies each.
www.findgreattraveldeals.net

www.findgreattraveldeals.net wrote on 11/02/14 12:53 AM

If you want to travel but don't think you can afford it, you should read on. You can get great travel deals with just a little bit of research.
www.travelingsales.net

www.travelingsales.net wrote on 11/02/14 12:53 AM

Traveling sales jobs can be some of the most financially rewarding sales jobs that there is. Many companies will pay top dollar to salespeople who are good at their craft and also don't mind traveling.
living-business

living-business wrote on 11/19/14 6:57 AM

As a consequence of various motives, the require for served living facilities have been rapidly growing currently - almost certainly mainly as a result of very idea that the forty somethings and beyond are now approaching the retirement.
smart green business

smart green business wrote on 11/19/14 6:57 AM

To become Green Organization has evident environmental positive aspects. Business managers who create the transition will likely increase profits and productivity while minimizing risk along with cost!
minority business solutions

minority business solutions wrote on 11/19/14 6:57 AM

Smaller minority businesses are facing a great deal of obstacles when looking to create the correct small organization marketing approaches. There are countless barriers for you to overcome using marketing including:
business theory

business theory wrote on 11/19/14 6:57 AM

Organization theories are most often in a new realm their own, but precisely what they are generally is yet another matter totally. The notion behind an enterprise theory is often a situation as well as result which has been proven true time and again in several business adjustments.
Professional Resumes

Professional Resumes wrote on 12/01/14 5:12 PM

Thank you for the update! Going to forward this to my peers. Looking forward to more!
jam tangan online

jam tangan online wrote on 01/22/15 3:12 AM

Nice to read your article! I am looking forward to sharing your adventures and experiences.
www.scorespro.com

www.scorespro.com wrote on 01/26/15 11:39 PM

In order to understand the of baseball, you must admit that for reasons uknown, humans use a natural need to conquer things. Whether it is to launch frustration, or simply just for entertaining, we try this even with out noticing.
mypetshop.org

mypetshop.org wrote on 02/13/15 4:41 AM

Are you experiencing a family pet, or are you currently planning on buying one? Either approach, there's a massive likelihood you will visit any pet go shopping. However, there are usually things you must look out there for if you are visiting family pet shops.
Dallas Auto transport company

Dallas Auto transport company wrote on 03/04/15 10:32 PM

I am also trying for this application.But did not get success yet.Is their any tips ?
studio dentistico roma

studio dentistico roma wrote on 04/03/15 11:16 PM

Lo studio Dentistico Roma Dottori Damis Resta Rossi Iommetti è situato nell'elegante quartiere Prati di Roma ed opera nel settore odontoiatrico dal 2005.
click

click wrote on 04/20/15 2:34 AM

Thank you for sharing this post here!!!!
Lomments

Lomments wrote on 04/21/15 5:16 AM

We Have All The Games Currency With Cheapest Price - Buy Fifa Coins, WOW Gold ETC.
Frances97

Frances97 wrote on 04/23/15 4:51 AM

Digital Photography Review (DPR), on the list of web's most trusted resources for everything things digital photography, has just completed its in-depth review of your Nikon D600. When Nikon announced the D600 back in September, it smashed all kinds of barriers when it came to your question of price vs. motion. Now, two months after announcement, the first review any world-renowned authority has been published.
Belinda28fy

Belinda28fy wrote on 04/23/15 11:09 PM

Content meaningful work, talent get full: <a href="http://www.uttrader.com/">www.uttrader.com</a>;
Belinda28fy

Belinda28fy wrote on 04/23/15 11:10 PM

Content meaningful work, talent get full: http: //www.uttrader.com/
Jenner

Jenner wrote on 05/08/15 7:46 AM

Exactly, good practising make every concept easier for you. These applications like www.dissertationclub.co.uk/ would be easy if you implements on expert advices.
johnwilliams

johnwilliams wrote on 06/09/15 7:38 AM

Best Fathers Day Images, Messages, Pictures,wishes,Wallpapers,sms,greetings, Cards,Fathers Day Poems,Quotes To Share On Whatsapp,Facebook,Twitter And Other Social Media.
<a href="http://www.happyfathersday.net.in/">happy fathers day quotes</a>
clothing manufacturer

clothing manufacturer wrote on 07/04/15 4:13 AM

The Cold Fusion technology can be used for the website optimization too. A fast website will be better viewed by search engines. I've performed some tests with that and it works well.
johnwilliams

johnwilliams wrote on 07/26/15 2:19 AM

Collection of best friendship day images, pictures, messages, quotes, sms, pics, greetings, cards, wishes, wallpapers, photos for sharing on whatsapp, facebook, twitter and other social media.
<a href="http://www.friendshipdayimages.org/">happy friendship day 2015 images</a>
Luxe

Luxe wrote on 11/18/15 6:42 AM

Yeahh Luxe.net izyyy
glaukoma sudut tertutup

glaukoma sudut tertutup wrote on 12/12/15 1:59 AM

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
Model Baju Gamis

Model Baju Gamis wrote on 02/28/16 8:45 AM

Aku gak ngerti tapi gapapa lah aku pen ikutan komen aja :)
Model Baju Batik

Model Baju Batik wrote on 02/28/16 8:46 AM

abi hyong ngiringan komen nya, wios kan?
haturnuhun..
Tutorial Hijab Modern

Tutorial Hijab Modern wrote on 02/28/16 8:46 AM

Bismillah Sukses
Michel

Michel wrote on 03/28/16 10:43 PM

Great and awesome. keep it continue....... http://www.butyskleppl.com/
mimi

mimi wrote on 04/21/16 12:08 AM

great and good , i like it <a href="http://goo.gl/dAKPYs">baju gamis syar'i</a>
Michel

Michel wrote on 08/14/16 6:00 AM

this is amazing work and please keep doing work like this and people will be so thankful to you soon, nike running shoes on sale http://www.roadrunnersneed.com/nike-c-1.html
Michel

Michel wrote on 08/18/16 4:40 AM

Your post is very informative and interesting. Acheter chaussures de running avec les derniers modèles et de la technologie au http://www.roadrunnerfr.com/
backlinks

backlinks wrote on 08/22/16 7:24 AM

Exactly, good practising make every concept easier for you. These applications like
lialezama

lialezama wrote on 08/22/16 10:14 PM

I would like to share this information on my social networking site so that any needy person can know about such place, check this site http://www.skleprun.com/ for more information.
susanna

susanna wrote on 09/08/16 11:29 AM

This is a nice post in an interesting line of content. Thanks for sharing this Under Armour Sportssko Udsalg Danmark www.skosportdk.com/under-armour-c-7.html
Click here

Click here wrote on 11/07/16 8:27 AM

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
Formal shoes

Formal shoes wrote on 11/18/16 7:01 AM

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.