?
Solved

Cold Fusion Optimization Techniques

Posted on 2003-03-07
43
Medium Priority
?
14,582 Views
Last Modified: 2013-12-24
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")
0
Comment
Question by:TallerMike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
43 Comments
 
LVL 10

Expert Comment

by:substand
ID: 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.

0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 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
0
 
LVL 17

Expert Comment

by:anandkp
ID: 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
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Expert Comment

by:myst007
ID: 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
0
 
LVL 10

Expert Comment

by:substand
ID: 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.

0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 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 ...

0
 
LVL 10

Expert Comment

by:substand
ID: 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.



0
 
LVL 10

Expert Comment

by:substand
ID: 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?

0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 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.
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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...
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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


0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 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
0
 
LVL 10

Expert Comment

by:substand
ID: 8106198
this quickly became database query optimization =)
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 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.

0
 
LVL 10

Expert Comment

by:substand
ID: 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.


0
 
LVL 1

Expert Comment

by:JUSTICE
ID: 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??
0
 
LVL 8

Expert Comment

by:raj_
ID: 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!!
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 

Expert Comment

by:bobdinski
ID: 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
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 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.
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 
LVL 17

Expert Comment

by:anandkp
ID: 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.
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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
0
 
LVL 1

Expert Comment

by:Ken-doh
ID: 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




 
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 
LVL 1

Expert Comment

by:Ken-doh
ID: 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 :|

0
 
LVL 4

Expert Comment

by:crosenblum
ID: 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?
0
 
LVL 8

Author Comment

by:TallerMike
ID: 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.
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 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.

:)
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8243769
:)
0
 
LVL 1

Expert Comment

by:Ken-doh
ID: 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 :)


0
 
LVL 4

Expert Comment

by:crosenblum
ID: 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?

0
 
LVL 1

Expert Comment

by:Ken-doh
ID: 8246458
advanced is over 85% in exam

standard is less than 85% and more than 60%

thats all
0
 
LVL 8

Author Comment

by:TallerMike
ID: 8307342
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8501721
PAQ'd and 250 points refunded

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 2

Expert Comment

by:netuser1976
ID: 8608880
Use CFScript as much as possible. You are one step closer..
0
 
LVL 2

Expert Comment

by:Cypher188
ID: 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">

0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question