Main Page Content
Ben Forta On Optimizing Cf4 Applications
Ben Forta, Allaire evangelist, presented "Optimizing ColdFusion 4 Applications" at the Toronto CF User Group meeting last night. Here's a summary of some of his strategies.
Use the Database
According to Ben, the single biggest culprit in poorly performing CF websites is the CF programmer trying to do the database's job. Because CF is a runtime interpretive environment, you should use the database wherever possible, particularly for- relational integrity
- triggers
- unique constraints
- sql aggregates and functions
Reuse Code
Use CFINCLUDE and Custom Tags (a powerful "black box" feature, especially in CF4+), to modularize your code and make it easier to maintain and optimize. Custom Functions will probably be available in CF5.Caching
Hard drives are "the only component in your computer with a mean time between failures actually stamped on them," said Ben. "They will disappear, but not any time soon." Cold Fusion supports three types of caching:- page level caching -- CF opens and reads a cfm page, translates it into P-code, and keeps it in cache; bump your 1024K default high enough to hold all the cfm pages in your site (the memory is not allocated, it's just an upper limit).
- page output cache -- use CFCACHE to cache dynamic output to simulate static pages (a great example is evolt's own FAQ page at http://evolt.org/faq/index.html)
- query result caching -- "How many times do you want to go to the database to get state codes to populate a drop down list? This being Canada, when was the last time you added a new province?" Ben asked. Many in the audience immediately shouted "Last April!" Not missing a beat, Ben came back with "And the time before that?" Another example where query result caching should be utilized is for "next N" queries, which otherwise would re-return the entire result set every time.
The evening concluded with a question-and-answer session briefly covering Spectra, JRun, and WDDX. If you ever get a chance to catch a Ben Forta presentation, I recommend it highly.