Question

Cold Fusion Optimization Techniques

Asked by: TallerMike

I'd like people to post their best/favorite optimization techniques for Cold Fusion. It's not really a question, but I'll give the points to the best idea after we've gotten enough comments.

Think of it not so much in answering this question, but as the number of other interested Cold Fusion programmers who might read this and not know. So no method is too simple!

I'll start it off with a few examples:

IFF is really slow, use <CFIF><CFELSE></CFIF> instead

(compare(expertName,"TallerMike") eq 0) is faster than (expertName eq "TallerMike")

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-03-07 at 14:40:41ID20542979
Topics

ColdFusion Application Server

,

ColdFusion Studio

Participating Experts
14
Points
0
Comments
43

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. cold fusion
    where can i find a free cold fusion tutorial on the web
  2. a cold fusion counter ?
    How to write a cold fusion counter script ?
  3. Is there anything simular to grep in Cold Fusion?
    Is there anything simular to grep in Cold Fusion? I am trying to extract a short string from a text file with Cold fusion. I am aware that this can be done with perl but in this instance I need to do it with Cold Fusion. Any help would be gladly accepted. jat@ecis.com
  4. Cold Fusion
    What is Cold Fusion?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: substandPosted on 2003-03-07 at 15:05:06ID: 8091544

separating your "code" from your "display" as much as possible promotes readability, and allows you to place all the code in a <cfscript> tag.  scripted CF runs much faster and more efficiently than tags.

 

by: danrosenthalPosted on 2003-03-07 at 16:19:16ID: 8091912

Interesting idea Taller...Just off the top of my head...


1.
<CFIF len(testvar)> is better than <CFIF testvar eq "">

2.
Use CFSWITCH instead of CFIF/CFELSE if possible.

3.
More for database optimization but..
Use Stored Procedures wherever you can. And where you can't, use CFQUERYPARAM for variables to protect your site from possible hackers and also to increase database performance. (Mike, I believe you mentioned this in a recent post)

-Dan

 

by: anandkpPosted on 2003-03-07 at 20:36:41ID: 8092649

Hi,

above all +

optimise queries using clustered indexes - these can improve the performance of the normal query upto 98% ... i've done this recently & realised how important this was.

use minimum processing at the front end - the backend has tremendous power's whihc r often unexplored ... use them instead - as right said above [for using stored procedures].
this heps in minimizing the CF & DB interaction & help speed up the process.

Using of cached queries ... wld help on hitting the DB server everytime.

use CFPROCESSINGDIRECTIVE to compress the HTML that is being send to the browser - helps in loaidng the HTML faster.

make more use of common include files / functions / tags ... these can be referenced using CFMODule to increase the performance as well.

if performance is of importance - then dynamic variables can be minimised & aviod the usuage of "evaluate" function as much as possible [this wld lead to writing more code - but if performance is priority then ... :)]

use CFC's as much as possible ...
also componenets cld be created for improving the performance toa  gr8 deal

there wld be a lot more - ... i'll get back on this :)

K'Rgds
Anand

 

by: myst007Posted on 2003-03-08 at 01:14:47ID: 8093299

PLUS

1. <CFPARAM NAME="MYAGE" DEFAULT="1000" TYPE="NUMERIC"> is faster than <CFSET MYAGE=1000>
2. Avoid Evaluate(), DE(), IIF()
3. <CFCACHE>
4. <CFFLUSH> for long DB queries
4. SQL Aggregate Functions

 

by: substandPosted on 2003-03-08 at 14:03:47ID: 8095323

here's something that i just remembered that most people don't know about (or at least not many people that i've talked to), but is VERY useful at times.  its not really "optimization", but its useful to know:

coldfusion (at least up until v5, i don't know about mx) returns the results of a query in an array form.

for example, if you have:

<cfquery name="blah" datasource="#datasource#">
 select name, id from members
</cfquery>

you can then access
 
blah.name[2]

to return the value of the second name in the query.

 

by: HamdyHassanPosted on 2003-03-08 at 14:27:20ID: 8095396

You deserve 100 points for this good idea, this topic will be a golden reference for future developers.

Let's start

* you always reference variables by it's scope, more readable and giving a break to CF engine
e.g.  FORM.user_is , Variable.app_name ...

 

by: substandPosted on 2003-03-08 at 15:04:55ID: 8095491

danrosenthal:

Just out of curiosity for your #2, why use cfswitch?  is it faster?  I mean, I use it when my if/else block would grow too large, but is it so efficient that i should use:

<CFSWITCH EXPRESSION=#booleanVariable#>
    <CFCASE VALUE="true">
       ...Do Something...
    </CFCASE>
</CFSWITCH>

rather than

<cfif booleanVariable>
    ...Do Something ...
</cfif>

...

please don't get offended at that (not that you would, but appearantly I'm an idiot and alot of people have gotten offended by what I say, thinking I'm being a smartass, when in fact i think i'm just asking reasonable questions or giving reasonable responses.)  I meant it as an actualt question.

Also, thanks for your #1 tip, it makes sense and I think I'll use it.  It was something I never thought of.



 

by: substandPosted on 2003-03-08 at 15:06:13ID: 8095494

here's a question while we're at it.

I always use "is" in my conditional statements, while I notice alot of people use "eq".  Is there a difference between the two, and if so, what is it and what makes one better than the other?

 

by: danrosenthalPosted on 2003-03-08 at 16:02:56ID: 8095718

about CFSWITCH: found this line in the ColdFusion Studio help docs... CFSWITCH provides better performance than a series of CFIF/CFELSEIF tags and the resulting code is easier to read.

As far as the definition of "a series of CFIF/CFELSE" tags, I would  guess 3 or more.

 

by: TallerMikePosted on 2003-03-09 at 06:59:35ID: 8097781

Excellent everyone! Keep them coming! I think that this post will help alot of people with optimization.

Some questions have come up about optimization eve which I find interesting. I've got answers to 2 of them (In part to the following link):

http://www.developer.be/index.cfm/fuseaction/BenchmarksList/GroupID/1/GroupName/ColdFusionBenchmarks.htm

Using 'is' is exactly the same as using 'eq', neither is faster.

And it is interesting to note that while CFSWITCH is easier to read, it is NOT faster for string comparison (at least according to these tests). Using compare in a series of CFIF/CFELSEIF/CFELSE statements will actually be faster...

 

by: heathprovostPosted on 2003-03-09 at 08:57:15ID: 8098088

This is kinda oldschool, but it is something I see in alot of people's code all the time even still...

Situation: You have a web based search against a rather large database and you are displaying the search results in a paged fashion (i.e. say 20 results per page). This is how I often see people coding this:

{The page expects a few url params, most importantly an order by clause (which field(s) to order on, and what row to start on (usually given as an absolute row number)}

<cfquery name="getdata" datasource="ds">
  SELECT *
  FROM bigtable
  ORDER BY #url.order#
</cfquery>
<cfoutput query="getdata" startrow="#url.startrow#" maxrows="20">
  ... query output
</cfoutput>

This is _horribly_ ineffecient if the resultset is even moderately large. This is because the entire resultset must be fetched from the SQL server for every page, regardless of the criteria given. It is much better to do something like this:

{The semantics here have changed a bit. We are no longer using an absolute row number as the starting point, but intead are using the id (primary key) of the last record fetched on the previous page. This only works if the table has a primary key of course}

<cfquery name="getdata" datasource="ds">
  SELECT TOP 10 *
  FROM bigtable
  WHERE id > #url.startid#
  ORDER by #url.order#
</cfquery>
</cfif>
<cfoutput query="test">
  ... query output
</cfoutput>

This version of the code will have the same effect, but the query will only return the needed rows instead of all of them. It code of course be extended to allow moving both forward and backwards through the results (either way) but I just want to give the nuts and bolts of it.

Another (often more effective) way to optimize this is to use a cached query combined with query on query to filter it, but that isnt really an optimization of code, rather a total change in design. This, however, could be grafted onto existing code quite easily most of the time.

Heath

 

by: heathprovostPosted on 2003-03-09 at 08:59:33ID: 8098096

SELECT TOP 10 should have been SELECT TOP 20 in the previous posting... Typo :)

Also, I ommitted the WHERE clause for clarity, the code would of course need to have a WHERE clause of some sort to be useful as a search. Adding it wouldnt change the functionality of the code.

Heath

 

by: TallerMikePosted on 2003-03-09 at 10:04:14ID: 8098268

It should be noted in that last example by heathprovost that it will only work if the records being returned are ordered by the ID being used filter the startID.

Example case:

messageID userName
1 TallerMike
2 substand
3 danrosenthal
4 anandkp
5 myst007
6 substand
7 HamdyHassan
8 substand
9 danrosenthal
10 TallerMike
11 heathprovost
11 heathprovost

Ordering this table by name gets us:

messageID userName
4 anandkp
3 danrosenthal
9 danrosenthal
7 HamdyHassan
11 heathprovost
11 heathprovost
5 myst007
2 substand
6 substand
8 substand
1 TallerMike
10 TallerMike (Why am I always last?)

<cfset startid = 1>
<cfquery name="getdata" datasource="ds">
 SELECT TOP 5 *
 FROM eeMessages
 WHERE messageID > #startid#
 ORDER by userID
</cfquery>

By the above method, viewing the top 5 would give us:

messageID userName
4 anandkp
3 danrosenthal
5 myst007
2 substand
1 TallerMike (Last...Again!)

Basically the first N (in this case 5) records, ordered by userID. Not the first 5 messages ordered by userID.

 

by: heathprovostPosted on 2003-03-09 at 12:14:18ID: 8098685

Yes, that is correct. This optimization method is messy and often requires carful thought in order to get the query right. But I have never run across a case where it cant be adapted to fit the needs required. I didnt want to get too detailed in my example, but since it came up all you have to do is something like this (using your example):

<cfset startid = 1>
<cfquery name="getEdgeRow" datasource="ds">
SELECT *
FROM eeMessages
WHERE messageID = #url.startid#
</cfquery>
<cfquery name="getdata" datasource="ds">
SELECT TOP 5 *
FROM eeMessages
WHERE #url.order# > '#evaluate("getEdgeRow." & url.order)#'
ORDER BY #url.order#
</cfquery>

This requires an extra query, but it is only fetching a single row and is off the pk, so it is relatively cheap. It uses that row to get the value of the last record of the field specified in the order by clause. That way, the query that is doing the actual fetch can use the order by field instead of the id field for its where clause, resulting in maintaining proper ordering.

Anyway, the point is merely that this type of optimization has a very significant payoff in terms of performance. I never said it was always easy to implement ;)

ps. I am cheating a bit with the single quotes. MSSQL lets you get away with using single quotes even if the field in question is a numeric type. You would have to add additional logic in order to deal with that if using another DB that isnt as forgiving.

Heath


 

by: heathprovostPosted on 2003-03-09 at 12:22:59ID: 8098729

Actually, that can be optimized a bit more...

<cfset startid = 1>
<cfquery name="getEdgeRow" datasource="ds">
SELECT #url.order# as startval
FROM eeMessages
WHERE messageID = #url.startid#
</cfquery>
<cfquery name="getdata" datasource="ds">
SELECT TOP 5 *
FROM eeMessages
WHERE #url.order# > '#startval#'
ORDER BY #url.order#
</cfquery>

This is better because it only fetches a single field value instead of the whole row in the first query, and it eliminates the need to use an evaluate statement.

Heath

 

by: heathprovostPosted on 2003-03-09 at 13:21:12ID: 8098918

Since we are optimizing :)

<cfset startid = 1>
<cfquery name="getdata" datasource="ds">
  SELECT TOP 5 *
  FROM eeMessages
  WHERE #url.order# > (SELECT #url.order# as startval FROM eeMessages WHERE messageID = #url.startid#)
  ORDER BY #url.order#
</cfquery>

Eliminated need for 2 queries and also eliminated possible problems with single quotes

 

by: TallerMikePosted on 2003-03-09 at 17:24:40ID: 8099912

I think we could start an entire post surrounding this idea in and of itself. I'd love to discuss it here, however I'd like to try not to clog this post with such specific pointers. Let me know if anyone wants to start an open ended discussion on this specific aspect of optimization. I'd be interested to hear everyones opinions there.

 

by: heathprovostPosted on 2003-03-10 at 00:48:26ID: 8101469

Fair enough. I dont think it is necessarily helpful to get into gory details anyway. This optimization can be generalized into a simple statement: If the size of the resultset is a bottleneck, make your queries return no more data than you need at the given moment. You should always attack bottlenecks when optimizing, i.e. dont try to make things faster if they are not a significant factor in overal performance. I would never try to do this kind of optimization on a result set that can be returned in less than say 200ms. While it would technically be faster with this optimization, it is very ugly and harder to maintain. But if the resultset takes 2000ms, and this code can reduce that to 20ms, that is a 100x speedup and I would think it would be then be worth it.

But I would point out that this is a much more significant optimization than most of what has been mentioned so far. Replacing string compares using eq with a compare statement for example is simply going from one O(n) solution to another O(n) solution, albeit one with a slightly smaller (n). These are both linear in nature. The payoff isnt that big generally. Personally, I avoid that kind of optimization as I find it muddies up the code.

Reducing your resultset to the minimum required size, however, is an O(1) optimization, i.e. constant. The time required to return a complete resultset is O(n). (n) gets bigger proportional to the size of the resultset. The bigger it is the longer it takes, and time grows proportionally with size.

But by returning only a fixed sized subset, you are turning it into an O(1) activity, at least from CF's perspective. It will (assuming you have a good SQL server that is indexed properly) take the same amount of time regardless of the number of rows of underlying data. So the more data involved, the bigger impact this has on overall speed.

Heath

 

by: substandPosted on 2003-03-10 at 13:45:23ID: 8106198

this quickly became database query optimization =)

 

by: crosenblumPosted on 2003-03-10 at 14:35:56ID: 8106536

My favorite tricks revolve around using the querysetcell for practically any need.

For example, instead of using dynamic form names, i have the same form names send multiple amounts of data.

But because of the way multiple form data in one form element comes back. Aka as a comma delimitted list.

Then it becomes easy to loop thru listlen of one of the form elements. And add it to a new query set cell.

Then once it's is added, you can output it.

Or what i have fun doing, is doing a query of queries to sort the data in querysetcell.

It is my favorite trick.

Because there is so much you can do with it, to help set up fake queries. Because queries are the starting point for almost every application starts with a query.

Lots of commenting and documentation, do not forget to end every cf comment with 3 dashes, if you start with 3 and end with 2, it can cause whole sections of code to be commented out. It is scary.

 

by: substandPosted on 2003-03-10 at 15:22:12ID: 8106811

while i like using that in some cases, the problem with using the same form field name for multiple fields, is also what's good about it: the comma delimited list.

you need to be sure that

1) a user is never going to enter a comma in thier response, as this obviously screws everything up.

2) either make every field required, or else be sure that no one is going to leave a field blank.  

I'm not sure if flagging a field as "required" will help in this situation, since the field names are the same. If the user just enters a value in one field, it might not require them to enter a value in all fields, because of the same name.  I'm not sure on this, as I haven't tried it, does anyone know?  

Also, blank fields will return something like:

val1,val2,,,val5

in which case, if you were expecting 5 values, the listlen is actually 3.  you can combat this by either making sure you <cfloop list="#form.fieldname#">, or parsing the list yourself for every comma using findnocase(...","...);
and or replacing it with " ,".

just wanted to mention that for people who might try that and get bugs for not doing it right.


 

by: JUSTICEPosted on 2003-03-12 at 05:59:38ID: 8119337

I have a Q about optimization... Which of the following is a better / faster practice??


1)

<cfoutput>
<TR>
<TD colspan="6">Date Run: #DateFormat(Now(), "MM/DD/YYYY")#</TD>
<TD colspan="8"><strong>Daily Planning Sheet</strong></TD>
<TD colspan="6">Day of the Week: #Dayofweek(Now())#</TD>
</TR>
</cfoutput>

Or

2)

<TR>
<TD colspan="6">Date Run: <cfoutput>#DateFormat(Now(), "MM/DD/YYYY")#</cfoutput></TD>
<TD colspan="8"><strong>Daily Planning Sheet</strong></TD>
<TD colspan="6">Day of the Week: <cfoutput>#Dayofweek(Now())#</cfoutput></TD>
</TR>

I guess this would depend on if it takes more processor time to look over the HTML for any coldfusion tags or not..  Any idea's on this??

 

by: raj_Posted on 2003-03-12 at 11:03:08ID: 8121653

Excellent thread Mike!

I personally feel there are 2 separate aspects to optimizing a ColdFusion application.
1) The ColdFusion templates and
2) The Database interaction

As for ColdFusion templates many excellent points have been mentioned already by Anand, Hamdy etc. Since I personally feel these points can never be over-emphasized – here I go:
1)     LOCKING: It is extremely important that all variables in shared scope, like session, application etc be LOCKED. Failing to do this can lead to disastrous and unexplainable server behavior and crashes
2)     SCOPING: Scope all variables. This particularly true even inside a <CFOUTPUT query=”mySQL”></CFOUTPUT> tag block. Scoping all the variables with mySQL prefix will be a very good practice.
3)     BE DISCRETE: Each tag used has a cost. It will be very costly for ColdFusion to process 10 <CFOUTPUT> as compared to 2 <CFOUTPUT> tags. It would be good to have minimal usage of CFOUPUT tag and use CFLOOP type=Query to loop through recordsets
4)     INDENTATION: For the love of god use the TAB key while coding. Trying to debug a 500 line single block ColdFusion Template is no fun.
5)     AVOID DB TRIPS: Use Caching and Query of Query features to avoid trips to the DB server. Use WDDX packets when trying to do pagination etc to avoid re-hits to the DB server
6)     STORED PROCS: Try using Stored Procedures instead of plain Queries. Stored Procs (usually) have a execution plan pre-compiled and hence its easier for the DB server to execute them
7)     ALL OF THE SUPERB POINTS MENTIONED HERE ABOVE

As for Sql there are few simple rules which can save a lot of CPU ticks. Again, most of them have already been mentioned here before.
     View the execution plan of the queries (of procedures) your write. (in Sql Server, turn on the Show Execution Plan option in query analyzer). Verify and ensure that proper indexes are being used. If not try to see if an indexed can be added or modified. Use the Index Tuning Wizard to identify indexes.
     Try and create efficient Queries and Procedure so that the DB engine will handle all the CPU intensive tasks and ColdFusion server just has to render the page. Avoid using cases where you have to use CFQUERY inside CFLOOPS, instead try to have the Stored Proc return the entire result set and use CFOUTPUT with group by clause to render the page.

Gotta go.. more thoughts later..
Once again Excellent thead!!

 

by: TallerMikePosted on 2003-03-12 at 11:31:13ID: 8121856

Something else to add, I'm a firm believer in developing with debugging turned ON. The Cold Fusion debugging is an excellent tool for optimization because it SHOWS you the amount of time spent on not only each query, but each template that is processed. These are invalueable tools for finding the spots that are taking the most time to execute.

Keep in mind that the first time you run a query it will take longer than subsequent times as the DB server may cache the execution plan on it's own. And Cold Fusion itself seems to take longer the first time a page is run.

 

by: bobdinskiPosted on 2003-03-14 at 11:52:01ID: 8138731

Make your queries inside your databse for large recordsets then, use the stored Procedure tag in Coldfusion to call allready made queries in your database.  Very valuable for optimization.

-Bob

 

by: crosenblumPosted on 2003-03-14 at 14:41:41ID: 8139929

Just published an article about my theories/thoughts of coldfusion on defusion.com's site.

http://www.defusion.com/articles/index.cfm?ArticleID=229
Purist Methodology Part Deux.

Basically the key in ColdFusion is finding the barometer in all levels of professional application development and moving yourself towards them.

From the Basic to the Advanced.

Commenting - Always Mandatory to comment the logic flow of your applications.
Documentation - Document Sites/Servers/Databases/Security
Project Management - Never back away from complete accuracy in projects.
Intranet - Project Mgmt and Communication
Coding Styles/Guidelines - Establish and Stand By them
Data Conversion - Always look for new ways to convert one kind of data to another. Data conversion is a skill that can be readily available to any of your apps.

A couple of advanced ones in my mind.

Cleaning/Maintenance - Make sure your sites/apps don't grow out of bounds. Be prepared to eliminating unnecessary files/folders and applications. Keep your sites/servers lean and mean.
Don't be afraid to try anything or ask anyone, that is exactly how we all learned.

Almost every cfer I have met, learned by doing, rather than going to some college course.

Methodologies are important, but it has to make sense. Some parts of fusebox do not make sense. Other parts do.

Pattern Analysis - As you get a lot more experience you can see and sense patterns in your applications, and how to best handle them.

I find my speediest application development comes after years of doing the same kind of application.

Sometimes I am not even concentrating on what I am coding on. I am just using my higher conscious/subconscious to automate my coding.

Just like Database tables have relationships, so do applications. That is what is called application framework.

I try to visualize an application in my head in 3d.

I add/remove different parts of the framework.

Okay I have a form here, what page do I want to send the form to? Do I have multiple form actions? Should this be on a seperate page or is it small enough to put on the same page as the form page.

Form-Action-Display and around it goes

So plan well and think well.

 

by: TallerMikePosted on 2003-03-14 at 15:20:40ID: 8140177

OK guys...we're getting a bit off topic here. We're looking for "Optimization Techniques" not "Programming Techniques and Methodologies".

If someone wants to start another question for "Best Programming Practicies", they may leave a link for it here.

 

by: anandkpPosted on 2003-03-24 at 00:59:11ID: 8193723

Application Design

At the center of any effort to create a scalable Web application should be intelligent application design. While the CF server provides native facilities to boost performance, it is ultimately in the hands of the application architect to ensure a high-performance application.

First in a designer's mind should be concern for efficient use of code. ColdFusion provides a number of language features that facilitate higher-performance applications. Cookies, arrays, includes and server variables all provide a means to store and manage code and content in ways that increase performance.

Second, in database centric applications, the quality and performance of an application often rests on the speed of query execution in the database. The developer should examine the SQL to ensure that it is querying the database in the fastest and most efficient way.

Third, developers should analyze where it is appropriate to segment application logic into different servers and files. When possible, developers may choose to use stored procedures to execute SQL calls and application logic, providing a high-performance, compiled architecture for database intensive operations. Related to using stored procedures is the use of distributed objects, where elements of application logic and database access are offloaded to a separate external object written in a compiled language such as C++, Delphi or VB5.


Using Server, Application and Session Variables for Persistent Data

ColdFusion Application Server 3.1 introduces a number of new variable scopes that can be used by developers to have fine-grained control over data caching and output. Often times a given application will have queries or data used that is not totally dynamic and which could be cached across user requests and applications. For instance, a company might have a page with a list of press releases. The list of press releases is stored in the database. However, the query to generate the list needs to run only once for a given application, and then have that data available to all users without having to re-query the database. Developers can take the results of a query and store it in a 'application' or 'server' scoped variable. Successive requests then no longer need to query the database, but instead would just use the query results stored in the application variable and output them onto the page.

Another example is an online service where each user has a unique set of preferences that are stored in a database. When a user accesses the service, ColdFusion can create a 'session' for that user. The query against the database of preferences could be run, and then the results stored in a 'session' variable. Future access to the preference data can then simply be called out of memory from the 'session' variable, instead of having to re-query the database again. When the session expires, the preference data also expires.


Use Verity Search '97 for Unstructured Data Searching

The ColdFusion Application Server includes an embedded high-performance text indexing and searching engine provided by Verity. The Search '97 engine provides developers with a platform for handling high-performance searches across unstructured textual data. This capability is a critical way of increasing performance in Web applications that involve searching large databases for information.

A particular feature of ColdFusion's integration with this technology is the ability to index and search textual content stored in a relational database, but using the high-performance Verity engine instead of SQL queries. SQL was originally designed for searching and manipulating highly structured data. Over time, however, the advantages of using a relational database to store unstructured textual data have become obvious, shifting developers to store and search textual data in relational databases. However, SQL is poorly suited to such searches. Using SQL to search thousands of textual memo fields or records can use unnecessary system processing cycles and typically yield poor matching and results.

Using ColdFusion's CFINDEX and CFSEARCH, it is easy to automatically index textual content into high performance Verity Collections. Then, when an end-user performs a keyword search against this data, it searches the Verity Collection, returning matches, including the primary key of the database record, allowing the developer to return other information about the record from the database. Implementing intelligent indexing and searching where appropriate can radically improve the performance of search-oriented ColdFusion applications.


Schedule Asynchronous, Resource Intensive Tasks for Offline Use

ColdFusion Application Server 3.1 introduces a page scheduling framework that allows the Web developer to schedule parts of an application to run in the background (asynchronously). This capability offers significant opportunities to increase application performance by scheduling resource intensive batch processing or background tasks to execute during non-peak hours. Scheduling can and should be used to handle file and content replication, database reporting, high volume messaging, application and database clean-up, and other activities that are not part of the real-time or transaction oriented parts of applications.


Application Techniques

In terms of scaling to support multiple servers, developers should be careful about the use of niceties like session variables, server variables, and client variables, as these are all tied to the server that is hosting the application. If you scale to multiple CF servers hosting the same application and are depending upon these, your application will break or misbehave.

CF Admin debug settings

Turn on all debug options when developing and check the processing times for your queries, and loops.

CF Studio and Homesite

Use the options in Studio to check the relative document weight

Poorly written SQL queries

Test your SQL queries with the ColdFusion Studio Query builder to make sure they are efficient. Studio will use the same ODBC driver that ColdFusion Sever will be using to connect.

Loops

Limit your use of nested loops.

Nested if's

Limit your use of nested CFIF ELSE statements. Try substituting IIF functions or non-nested CFIF statements.

# evaluations

Complex dynamically constructed expressions will negatively affect performance.

Optimizing performance when using variables

You can improve performance by always qualifying your variables with the proper scope. For example, both forms of the following variable are permitted. However, the example that includes a scoping prefix will be evaluated more quickly than the unscoped example.

CFOUTPUT vs. CFLOOP

Use a CFOUTPUT query instead of CFLOOP query wherever possible. A loop over a query repeats for every record in the query result set. The CFLOOP results are just like a CFOUTPUT. During each iteration of the loop the columns of the current row will be available for output. The advantage of using CFLOOP instead of a CFOUTPUT is that you can use any CFML tag within a CFLOOP. CFOUTPUT is restricted to a limited number of tags to increase its performance.

CGI vs. Web Server APIs

We recommend using the Web Server api's and not cgi

The Common Gateway Interface (CGI) was introduced as a standard protocol for extending the functionality of Web servers with additional applications. Most CGI applications are simple executables that are launched every time they are requested. ColdFusion uses a more robust architecture. The ColdFusion Application Server runs as a multi-threaded system service and handles all of the complicated processing. The Application Server communicates with the Web server either through a very small CGI executable referred to as the stub (CFML.EXE) or through a native Web server API.

As Web servers have developed, each vendor has introduced and implemented an application-programming interface (API) for their server. The native Web server APIs offer additional features and significantly increased performance. Instead of launching a CGI executable, servers supporting an API communicate directly with the ColdFusion application server through a DLL.

Arrays

ArrayResize

Resets an array to a specified minimum number of elements. ArrayResize can provide some performance gains if used to size an array to its expected maximum. Use ArrayResize immediately after creating an array with ArrayNew for arrays greater than 500 elements.

Array objects can be created by assigning an existing array to a new variable:

 
<cfset myarray2 = myarray>

In this case, a separate copy of the data in myarray is copied to myarray2. Changes made in myarray are not reflected in myarray2. It is very important to understand that such assignments are very resource-intensive since the entire array is copied from one variable to the other. This operation can significantly affect performance when large arrays are involved.

CFPOP

Two retrieve options are offered to maximize performance. Message header information is typically short and therefore quick to transfer. Message text and attachments can be very long and therefore take longer to process.

CFHTTP

Use the resolveUrl=yes only when needed.

LS.... Locale specific functions in CF3.1

The locale specific functions are slower than the equivalent English only...

CFFILE

Extensive use of CFFILE will create a performance problem because of the slow nature of disk I/O. Explore other options, for example stored procedures or other database functions.or system calls.

CFQUERY

The BLOCKFACTOR attribute of CFQUERY controls how many records are retrieved by ColdFusion Server from the database. When not specified, BLOCKFACTOR defaults to 1, which means that the ColdFusion Server retrieves records 1 at a time. If, on average, a specific query returns 30 records, you should set the BLOCKFACTOR attribute to 30, which will improve communication performance between CF Server and your database. The BLOCKFACTOR parameter can be set from 1 to 100. Also check out this case study on Optimizing ColdFusion Queries.

CFSET

A general comment about good CFML coding style. We suggest that all CFML developers replace

 
<cfset #foo# = "#bar()#">

with the much simpler and more efficient
<cfset foo = bar()>
ColdFusion Administrator settings

Beyond efficient application design, there are a number of additional ColdFusion server settings that will allow for higher performance applications.

Caching Settings

As noted above, ColdFusion's server administrator provides a means to tweak caching settings for pages and database connections.

Page caching settings also provide a very easy way to increase performance on the server. As a general rule, it is useful to set the amount of memory allocated for page caching to the total size in kilobytes of all of the pages used in applications on the server. This will ensure that all applications are automatically cached and JIT compiled in memory, completely eliminating file I/O overhead and first-pass code interpretation. The only constraint on this is total amount of memory on the system. Note, however, that it is extremely rare that the total K of pages will exceed the available memory on the machine. In the case that the cache size is set lower than the total size of pages, ColdFusion will use a FIFO processing model on page requests. This means that the most commonly accessed pages will almost certainly always be cached in memory. (Note: the above discussion pertains to server-wide settings, as opposed to an individual application, because currently the caching settings can be set on a server-side basis only).

There is no harm however in setting page cache to a much higher setting as ColdFusion will use what it needs when it needs it and let it go when it is through with it.

This setting should represent the upper limit that ColdFusion will use. Set it high.

Thread Settings or simultaneous requests

A critical setting that can be tweaked to increase performance is the number of simultaneous requests that the ColdFusion server will execute at any given time. This setting is loosely associated with the number of threads. The general rule is to set the simultaneous requests setting to 2-3 times the number of CPUs on the system. So, if the server has two processors, the number of simultaneous requests for the ColdFusion server should be set to 4-6. In this case, if and when there are more than two threads being requested, ColdFusion automatically queues additional requests until one of the other two is freed up. Setting the number of allowed threads much much higher than the number of CPUs will result in a degraded performance, because the ColdFusion server must then attempt to manage the multiple thread execution even though the OS will not execute additional threads until one of the processors is free.

In CF 3.0 the default setting is 15... Reset it to 2-3 times the number of processors on the server machine.

How to limit simultaneous requests CF Server settings

To set the server limit for simultaneous requests, run the ColdFusion Administrator. The first page displayed in the CF Administrator is the ColdFusion Server Settings page. The first setting on the page is the "Limit Simultaneous Requests" setting.

You can specify the limit that is appropriate for your configuration in the space provided for the setting. The checkbox to the left of the setting must be checked in order for the setting to take effect. If the checkbox is not checked, ColdFusion will attempt to process all requests that are sent by the web server. Depending on the hardware configuration of your server, this could potentially degrade performance. If ColdFusion attempts to process more requests than your server can handle (based on configuration), the server could possibly stop responding.

Limit simultaneous connections ---Datasources CF settings

As a general rule, the number of allowed connections to a database should be set to a number depending on the following:

the estimated user load, and
the amount of memory on the machine.
For higher numbers of users with a machine with lots of RAM, connection settings should be larger (e.g. 5 - 10 ).If you want to limit the total database connections, you must set that under "data sources" tab. Here, select your data source and this will limit the number of connections to the database. If your database can't keep up with CF, you should begin to see errors like "timeout getting connection to Datasource". If your CF machine is bogged down processing CF templates, you start getting timeouts and "server busy".

Maintain Database Connections - Datasources CF settings

This option is checked by default. What this setting does is that when a request is made from ColdFusion to a database it makes the database connection (first time only) and keeps it open to reuse for each subsequent database request. The connection is dropped only when the ColdFusion Service is stopped. If this setting is not used each database request made via ColdFusion would have to

Establish a connection to the database,
fulfill the request, and
Disconnect from the database.
Take these activities and multiply them by every database request made via ColdFusion and you can understand the performance implications.

Scheduling and Static Page Generation

With the release of ColdFusion Application Server 3.1 (Fall 1997), it is now possible to automatically generate static-pages from dynamic content stored in databases. Using a built-in scheduling engine, developers can automatically create static pages from dynamic data, substantially increasing the speed of page delivery to end-users without sacrificing the productivity and cost savings of using dynamic templates and database management of Web content.
This facility can be very useful for applications that do not require user interactions or customized output, such as a daily sales report, corporate directories, statistical reports, and batch processing of transaction files.
You can schedule application page execution to run on a daily, weekly, or monthly basis and specify a time of day for execution. You can also schedule a page to be run once on a specified date or at a regular interval during the day.
When a scheduled template executes, a message is written to a schedule log file, which specifies the name of the scheduled action, the application page that was executed, and whether the page executed successfully or not.
To access the scheduling facility, open the ColdFusion Administrator and click the Scheduler tab.

 

by: TallerMikePosted on 2003-03-24 at 06:27:17ID: 8195272

It should be noted that this and other information is available on Macromedias website through the following link:

http://www.macromedia.com/support/coldfusion/ts/documents/tn17125.htm

Other important technotes are availble through Macromedia at the following URL:

http://www.macromedia.com/support/coldfusion/technotes.html

 

by: Ken-dohPosted on 2003-03-31 at 06:32:23ID: 8238665



QUOTE "use CFC's as much as possible ... "

NO CFC's are 10% slower to execute as are custom tags.

there is a thin line between developing quicker and better code and developing for an optimisted site.


Give as much work as you can to the database.
stored procedures, default values etc etc.

no more than 100 lines of code per page:

use cfoutput as little as possible ie only where absolutley neccissary


USE PHP its faster :P

DO NOT USE ACCESS EVER mysql baby :)
DO NOT USE ODBC CONNECTIONS WHERE POSSIBLE

use <form> NOT <cfform>

write to database BLOBS not files
 
dont use windows hosting Linux is 30% faster

cache queries

complie all your pages before going live

avoid loops where possible


hope these help




 

 

by: TallerMikePosted on 2003-03-31 at 06:55:40ID: 8238831

Thankyou everyone for your responses. I've left you all 25 point questions (250/10 experts) for your responses. Please pick them up. I will leave this forum open for a while and see if we can get any other tips.

If anyone finds any other sites that have actual benchmarks like the following site, I would be interested to see:

http://www.developer.be/index.cfm/fuseaction/BenchmarksList/GroupID/1/GroupName/ColdFusionBenchmarks.htm

***********************************************************************************************************************************************
***********************************************************************************************************************************************

I'm considering doing a similar post in the JavaScrip area. Does anyone actually know any JavaScript optimization techniques or think this might be a useful post? Let me know by the email in my profile and I will send you a link if it materializes.

 

by: Ken-dohPosted on 2003-03-31 at 07:21:00ID: 8239025

how do i collect the points?? did i get any???

and as for benchmarks... for some reason there really hard to find. just went on a hunt in google :|

 

by: crosenblumPosted on 2003-03-31 at 09:44:00ID: 8240018

I have read about cfc, sounds interesting, only if you believe in a world of not having the complete code in front of you to make sure that all aspects of it do exactly what you want.

I believe in cfincludes, for navigation, modules any functioning i do as a cfinclude. It's simpler and better performance.

But like anything, can be overdone, and led to over-kill..

I agree with the <form> vs <cfform>

The major key is to understand how to maximize the workload for the component that can handle that workload the best.

Databases add more and more complexity and power, in able to for example do complex logic, return html parsed data, so as to do a simple cfoutput around a field.

That is instead of having ColdFusion do the same logic work and then display it.

It's always about finding that balance.

Right about now, I have a standard I use for creating display control pages.

Where you have data to display in excel spreadsheet, with all the natural controls. Sorting, Searching, Re-arranging in any way possible.

Once you get the knack for that, you can plop it in, and then adjust to what kind of data, controls needed, and speedily have it done in a couple of hours.

What other kinds of applications can you guys easily churn out?

Also what are best ways to document your skill/application level? do you guys use porfolio's if so how?

 

by: TallerMikePosted on 2003-03-31 at 09:50:37ID: 8240063

Ken-doh, look for a question posted in the Cold Fusion forum with your name on it. Put in a response, and I will accept it as an answer and award you points.

 

by: crosenblumPosted on 2003-03-31 at 13:24:48ID: 8241405

You know what would be really nice?

If we can take all this content, and work together, to make this an article or book.

Just my thought, I love this kind conversation, we definitely have some high quality minds here.

Even if I don't always agree with them.

:)

 

by: anandkpPosted on 2003-03-31 at 23:22:07ID: 8243769

:)

 

by: Ken-dohPosted on 2003-03-31 at 23:48:03ID: 8243877

QUOTE "Also what are best ways to document your skill/application level? do you guys use porfolio's if so how? "


best way is to get a MM advanced certification of CF and flash

we just joined the partner scheme with them so we can get cheap exams :)


 

by: crosenblumPosted on 2003-04-01 at 06:40:01ID: 8246025

Thanks...

Right now i am working on training to get the basic cfmx certification since cf5 certification expires in december.

Is it that much different between basic and advanced cf?

 

by: Ken-dohPosted on 2003-04-01 at 07:43:34ID: 8246458

advanced is over 85% in exam

standard is less than 85% and more than 60%

thats all

 

by: moduloPosted on 2003-05-10 at 14:38:44ID: 8501721

PAQ'd and 250 points refunded

modulo

Community Support Moderator
Experts Exchange

 

by: netuser1976Posted on 2003-05-29 at 13:34:28ID: 8608880

Use CFScript as much as possible. You are one step closer..

 

by: Cypher188Posted on 2004-03-23 at 11:45:02ID: 10660949

If you have a large amount of CF code on a page, try cutting down on the whitespace using

<cfsetting enablecfoutputonly="Yes">

Just remember after the code to put

<cfsetting enablecfoutputonly="No">

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...