SlideShare a Scribd company logo
1 of 15
Muahahaha! I just bit a byte! Why is my code so slow? Caching & Performance In ColdFusion Presented By DenardSpringle NVCFUG June 2011
Programming For Speed Write OOP Applications OOP applications run faster and perform better than procedural coded applications. OOP application’s use of encapsulation allows only those functions which need to be fired to fire, and those that don’t… don’t. Java, the underlying engine behind ColdFusion, is a true Object Oriented language. OO in ColdFusion has been developed to map as much as possible to the Java model that underlies the ColdFusion engine. This allows CF code to execute faster when written in an OO fashion.It also makes for happy developers, managers andcustomers.  O… O… Who?
Programming For Speed Exit As Quickly As Possible Logic in applications should always be written to exit as quickly as possible under all circumstances. Programmers have a tendency to write logic that checks for error conditions passively (at the end) rather than actively (at the beginning). This is a time honored tradition and one that is continually perpetuated in coding books. Stop it! Always check for error conditions first and plan the fastest exit strategy for all code. The less code that has to execute, the faster your application will run. Where’s the Exit?!
Programming For Speed Limit Nested Loops Nested loops are sometimes unavoidable, but they should be avoided whenever possible. Nested looping is both a blessing and a curse to developers. On the one hand it offers much needed functionality to iterate over multiple sets of inter-related data points. On the other hand, it kills servers. There are often alternatives to nested loops that developers ignore (mapping your data into a struct, for example) and many developers simply abuse the ability to nest loops without realizing the implicationsfor the performance of the application. I’m Loopy!
Programming For Speed Know Your ColdFusion ColdFusion offers a number of handy functions which should be avoided like the plague. ColdFusion is great. It gives us things like inline if (IIF) which one would logically assume runs as quickly as an if-then-else, but that’s a poor assumption. There are a number of functions in ColdFusion that don’t operate on the premise many developers think they do (structFind(), <cfmodule>, incrementValue(), etc.). As such, avoiding the processor intensive functions for those that behave better is always a preferred choice (e.g. struct.key, <cfinclude>, a=a+1). Uhh...
Programming For Speed Test Execution Speed The most often overlooked data point in testing is execution speed. Testing your code for execution speed is key to understanding which functions take too long. Database queries, math intensive reporting and internet protocol requests are no brainers for taking a long time and are often suspect enough to improve application performance significantly. There are other, less obvious, suspects to consider however – locking shared scope variables, for example. Using GetTickCount()  at the beginning and end of your functions will help you isolate problem areas and keep you from pulling out hair.  Faster! Faster!
Programming For Speed Use Stored Procedures Stored procedures take away much of the overhead involved with dealing with database queries. Stored procedures take a tremendous load off of your ColdFusion server and place it squarely in the hands of your database server. Understand that this is literally a transfer of CPU and memory load from your application server to your database server.  Stored procedures execute faster on most database servers than a query does from ColdFusion so it is typically a win/win situation. I should store *this* guy!
Cashing In On Cache Use Caching Caching is a fancy way of saying – keep this just as it is and give it to anyone who asks for it. For performance benefits, nothing beats caching. Caching of pages and queries, and indeed with ORM, allows you to provide quicker responsiveness for both static and dynamic* content. Pages and queries (e.g. ‘US States’ table in a DB) that never change should always be cached. ColdFusion doesn’t have to process the page or the query again until the cache expires, providing instant-on access to pages andcritical data (e.g. reporting). *dynamic content that changes infrequently Cash?!
Cashing In On Cache Page Caching <cfcachetimespan="#CreateTimespan(1, 0, 0, 0)#" directory="e:/temp/page_cache“> You tell ColdFusion to cache the page results by putting a cfcache tag on your ColdFusion page before code that outputs text. The tag lets you specify the following information: Whether to cache the page results on the server, the client system, or both. The default is both.  The directory on the server in which to store the cached pages.  The time span that indicates how long the page lasts until it is automatically flushed.  Oh, *Cache*
Cashing In On Cache Partial Page Caching <cfsavecontentvariable=“SESSION.myVar”></cfsavecontent> One handy but not very obvious way to use <cfsavecontent> is in the Application or Session scope of your application (typically in OnApplicationStart and/or OnSessionStart). By saving infrequently changing but frequently presented complex data in this way you can significantly decrease individual page load times. Because of the overhead of locking shared scope variables, use this technique only if the processing overhead of generating the output is more than theprocessing overhead of locking the shared scope.
Cashing In On Cache Query Caching <cfquerydatasource=“myds" name=“qGetStates" cachedWithin="#CreateTimeSpan(0,1,0,0)#">  The cfquery tag cachedWithin attribute tells ColdFusion to save the results of a database query for a specific period of time. This way, ColdFusion accesses the database on the first page request, and does not query the database on further requests until the specified time expires. Using the cachedWithin attribute can significantly limit the overhead of accessing databases that do not change rapidly. This technique is useful if the database contents only change at specific, known times, or the query does not require up-to-date results.(e.g. Google Adwordsreports are delayed 1 hr.) Day, Hour, Minute, Second!
Cashing In On Cache Flushing The Page Cache <cfcacheaction=“flush” [directory="e:/temp/page_cache“]> You can use the cfcache tag with the action="flush" attribute to immediately flush one or more cached pages. You can optionally specify the directory that contains the cached pages to be flushed and a URL pattern that identifies the pages to flush. If you do not specify a URL pattern, all pages in the directory are flushed. The URL pattern can include asterisk (*) wildcards to specify parts of the URL that can vary. If you have a ColdFusion function that updates data that you use in cached pages, that function should include a cfcache tag that flushes all pages that use the data. FLUSH!
Cashing In On Cache Flushing The Query Cache <cfquerydatasource=“myds" name=“qGetStates" cachedWithin="#CreateTimeSpan(0,0,0,0)#">  One of the first hurdles most developers face implementing query caching is how to undo the cache. Often in testing phases one discovers the database table didn’t have all the data it needed or needs a new field (or two) ‘manager special’ but one already has a cached query and doesn’t understand why they’re always getting the same results. I know it seems obvious, but it really isn’t when you first play with query caching ;)Setting your cachedWithintimespan to nothing (0,0,0,0)flushes the cached query and immediately calls thedatabase for your precious missing data! w00t! That’s what she said!
Cashing In On ORM Cache ORM and Caching – Session and Secondary Level Caches Cache data of a persistent object <cfcomponent persistent="true" schema="APP" table="Artists" cachename="artist" cacheuse="read-only"> Cache the association data of a persistent object <cfpropertyname="art" fieldtype="one-to-many" cfc="CArt" fkcolumn="ArtID" cachename="ArtistArts" cacheuse="read-only"> Cache query data availableArts= ORMExecuteQuery("from CArt where issold=0", {}, false, {cacheable=true, cachename="availableArtsQuery"}); See the Developing ColdFusion 9 Applications guide / ColdFusion ORM / Performance optimization / Cachingsection for full details of ORM caching techniques. Nom NomNom
Additional Resources ORM and Caching – Session and Secondary Level Caches Optimizing ColdFusion Applications There is no blog post for ColdFusion tags to avoid!! Performance tuning ColdFusion servers  We hope you enjoyed this! w00t!

More Related Content

What's hot

Introduction to Magento Optimization
Introduction to Magento OptimizationIntroduction to Magento Optimization
Introduction to Magento OptimizationFabio Daniele
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Ajax Load Testing Concerns By Eric Beland
Ajax Load Testing Concerns By Eric BelandAjax Load Testing Concerns By Eric Beland
Ajax Load Testing Concerns By Eric BelandTestomatix
 
Eric Beland Ajax Load Testing Considerations
Eric Beland Ajax Load Testing ConsiderationsEric Beland Ajax Load Testing Considerations
Eric Beland Ajax Load Testing ConsiderationsAjax Experience 2009
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itOtto Kekäläinen
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Jason Ragsdale
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with PerlPerrin Harkins
 
dh-slides-perf.ppt
dh-slides-perf.pptdh-slides-perf.ppt
dh-slides-perf.ppthackday08
 
Tulsa tech fest 2010 - web speed and scalability
Tulsa tech fest 2010  - web speed and scalabilityTulsa tech fest 2010  - web speed and scalability
Tulsa tech fest 2010 - web speed and scalabilityJason Ragsdale
 
Use Xdebug to profile PHP
Use Xdebug to profile PHPUse Xdebug to profile PHP
Use Xdebug to profile PHPSeravo
 
Stampede con 2014 cassandra in the real world
Stampede con 2014   cassandra in the real worldStampede con 2014   cassandra in the real world
Stampede con 2014 cassandra in the real worldzznate
 
LCA2014 - Introduction to Go
LCA2014 - Introduction to GoLCA2014 - Introduction to Go
LCA2014 - Introduction to Godreamwidth
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...ColdFusionConference
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCLPax Dickinson
 
Scalabe MySQL Infrastructure
Scalabe MySQL InfrastructureScalabe MySQL Infrastructure
Scalabe MySQL InfrastructureBalazs Pocze
 
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
Scale ColdFusion with Terracotta Distributed Caching for EhchacheScale ColdFusion with Terracotta Distributed Caching for Ehchache
Scale ColdFusion with Terracotta Distributed Caching for EhchacheColdFusionConference
 

What's hot (20)

Introduction to Magento Optimization
Introduction to Magento OptimizationIntroduction to Magento Optimization
Introduction to Magento Optimization
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Ajax Load Testing Concerns By Eric Beland
Ajax Load Testing Concerns By Eric BelandAjax Load Testing Concerns By Eric Beland
Ajax Load Testing Concerns By Eric Beland
 
Eric Beland Ajax Load Testing Considerations
Eric Beland Ajax Load Testing ConsiderationsEric Beland Ajax Load Testing Considerations
Eric Beland Ajax Load Testing Considerations
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize it
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with Perl
 
dh-slides-perf.ppt
dh-slides-perf.pptdh-slides-perf.ppt
dh-slides-perf.ppt
 
Tulsa tech fest 2010 - web speed and scalability
Tulsa tech fest 2010  - web speed and scalabilityTulsa tech fest 2010  - web speed and scalability
Tulsa tech fest 2010 - web speed and scalability
 
Use Xdebug to profile PHP
Use Xdebug to profile PHPUse Xdebug to profile PHP
Use Xdebug to profile PHP
 
Stampede con 2014 cassandra in the real world
Stampede con 2014   cassandra in the real worldStampede con 2014   cassandra in the real world
Stampede con 2014 cassandra in the real world
 
LCA2014 - Introduction to Go
LCA2014 - Introduction to GoLCA2014 - Introduction to Go
LCA2014 - Introduction to Go
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCL
 
Scalabe MySQL Infrastructure
Scalabe MySQL InfrastructureScalabe MySQL Infrastructure
Scalabe MySQL Infrastructure
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
Scale ColdFusion with Terracotta Distributed Caching for EhchacheScale ColdFusion with Terracotta Distributed Caching for Ehchache
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
 
Exploring App fabric
Exploring App fabricExploring App fabric
Exploring App fabric
 

Similar to Caching & Performance In Cold Fusion

Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Web Directions
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageBinary Studio
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisationgrooverdan
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
"Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment""Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment"webhostingguy
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Robert MacLean
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Timothy Fisher
 
Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012eballisty
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Bolke de Bruin
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbsvarien
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9Nuno Godinho
 

Similar to Caching & Performance In Cold Fusion (20)

Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storage
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
"Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment""Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment"
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbs
 
ASH and AWR on DB12c
ASH and AWR on DB12cASH and AWR on DB12c
ASH and AWR on DB12c
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
 

More from Denard Springle IV

ColdFusion_Code_Security_Best_Practices_NCDevCon_2015
ColdFusion_Code_Security_Best_Practices_NCDevCon_2015ColdFusion_Code_Security_Best_Practices_NCDevCon_2015
ColdFusion_Code_Security_Best_Practices_NCDevCon_2015Denard Springle IV
 
Touch Screen Desktop Applications
Touch Screen Desktop ApplicationsTouch Screen Desktop Applications
Touch Screen Desktop ApplicationsDenard Springle IV
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionDenard Springle IV
 
Securing Your Web Applications in ColdFusion
Securing Your Web Applications in ColdFusionSecuring Your Web Applications in ColdFusion
Securing Your Web Applications in ColdFusionDenard Springle IV
 

More from Denard Springle IV (8)

ColdFusion_Code_Security_Best_Practices_NCDevCon_2015
ColdFusion_Code_Security_Best_Practices_NCDevCon_2015ColdFusion_Code_Security_Best_Practices_NCDevCon_2015
ColdFusion_Code_Security_Best_Practices_NCDevCon_2015
 
Team CF Advance Introduction
Team CF Advance IntroductionTeam CF Advance Introduction
Team CF Advance Introduction
 
Touch Screen Desktop Applications
Touch Screen Desktop ApplicationsTouch Screen Desktop Applications
Touch Screen Desktop Applications
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusion
 
ColdFusion Coding Guidelines
ColdFusion Coding GuidelinesColdFusion Coding Guidelines
ColdFusion Coding Guidelines
 
Securing Your Web Applications in ColdFusion
Securing Your Web Applications in ColdFusionSecuring Your Web Applications in ColdFusion
Securing Your Web Applications in ColdFusion
 
ColdFusion ORM
ColdFusion ORMColdFusion ORM
ColdFusion ORM
 

Caching & Performance In Cold Fusion

  • 1. Muahahaha! I just bit a byte! Why is my code so slow? Caching & Performance In ColdFusion Presented By DenardSpringle NVCFUG June 2011
  • 2. Programming For Speed Write OOP Applications OOP applications run faster and perform better than procedural coded applications. OOP application’s use of encapsulation allows only those functions which need to be fired to fire, and those that don’t… don’t. Java, the underlying engine behind ColdFusion, is a true Object Oriented language. OO in ColdFusion has been developed to map as much as possible to the Java model that underlies the ColdFusion engine. This allows CF code to execute faster when written in an OO fashion.It also makes for happy developers, managers andcustomers.  O… O… Who?
  • 3. Programming For Speed Exit As Quickly As Possible Logic in applications should always be written to exit as quickly as possible under all circumstances. Programmers have a tendency to write logic that checks for error conditions passively (at the end) rather than actively (at the beginning). This is a time honored tradition and one that is continually perpetuated in coding books. Stop it! Always check for error conditions first and plan the fastest exit strategy for all code. The less code that has to execute, the faster your application will run. Where’s the Exit?!
  • 4. Programming For Speed Limit Nested Loops Nested loops are sometimes unavoidable, but they should be avoided whenever possible. Nested looping is both a blessing and a curse to developers. On the one hand it offers much needed functionality to iterate over multiple sets of inter-related data points. On the other hand, it kills servers. There are often alternatives to nested loops that developers ignore (mapping your data into a struct, for example) and many developers simply abuse the ability to nest loops without realizing the implicationsfor the performance of the application. I’m Loopy!
  • 5. Programming For Speed Know Your ColdFusion ColdFusion offers a number of handy functions which should be avoided like the plague. ColdFusion is great. It gives us things like inline if (IIF) which one would logically assume runs as quickly as an if-then-else, but that’s a poor assumption. There are a number of functions in ColdFusion that don’t operate on the premise many developers think they do (structFind(), <cfmodule>, incrementValue(), etc.). As such, avoiding the processor intensive functions for those that behave better is always a preferred choice (e.g. struct.key, <cfinclude>, a=a+1). Uhh...
  • 6. Programming For Speed Test Execution Speed The most often overlooked data point in testing is execution speed. Testing your code for execution speed is key to understanding which functions take too long. Database queries, math intensive reporting and internet protocol requests are no brainers for taking a long time and are often suspect enough to improve application performance significantly. There are other, less obvious, suspects to consider however – locking shared scope variables, for example. Using GetTickCount() at the beginning and end of your functions will help you isolate problem areas and keep you from pulling out hair.  Faster! Faster!
  • 7. Programming For Speed Use Stored Procedures Stored procedures take away much of the overhead involved with dealing with database queries. Stored procedures take a tremendous load off of your ColdFusion server and place it squarely in the hands of your database server. Understand that this is literally a transfer of CPU and memory load from your application server to your database server. Stored procedures execute faster on most database servers than a query does from ColdFusion so it is typically a win/win situation. I should store *this* guy!
  • 8. Cashing In On Cache Use Caching Caching is a fancy way of saying – keep this just as it is and give it to anyone who asks for it. For performance benefits, nothing beats caching. Caching of pages and queries, and indeed with ORM, allows you to provide quicker responsiveness for both static and dynamic* content. Pages and queries (e.g. ‘US States’ table in a DB) that never change should always be cached. ColdFusion doesn’t have to process the page or the query again until the cache expires, providing instant-on access to pages andcritical data (e.g. reporting). *dynamic content that changes infrequently Cash?!
  • 9. Cashing In On Cache Page Caching <cfcachetimespan="#CreateTimespan(1, 0, 0, 0)#" directory="e:/temp/page_cache“> You tell ColdFusion to cache the page results by putting a cfcache tag on your ColdFusion page before code that outputs text. The tag lets you specify the following information: Whether to cache the page results on the server, the client system, or both. The default is both. The directory on the server in which to store the cached pages. The time span that indicates how long the page lasts until it is automatically flushed. Oh, *Cache*
  • 10. Cashing In On Cache Partial Page Caching <cfsavecontentvariable=“SESSION.myVar”></cfsavecontent> One handy but not very obvious way to use <cfsavecontent> is in the Application or Session scope of your application (typically in OnApplicationStart and/or OnSessionStart). By saving infrequently changing but frequently presented complex data in this way you can significantly decrease individual page load times. Because of the overhead of locking shared scope variables, use this technique only if the processing overhead of generating the output is more than theprocessing overhead of locking the shared scope.
  • 11. Cashing In On Cache Query Caching <cfquerydatasource=“myds" name=“qGetStates" cachedWithin="#CreateTimeSpan(0,1,0,0)#"> The cfquery tag cachedWithin attribute tells ColdFusion to save the results of a database query for a specific period of time. This way, ColdFusion accesses the database on the first page request, and does not query the database on further requests until the specified time expires. Using the cachedWithin attribute can significantly limit the overhead of accessing databases that do not change rapidly. This technique is useful if the database contents only change at specific, known times, or the query does not require up-to-date results.(e.g. Google Adwordsreports are delayed 1 hr.) Day, Hour, Minute, Second!
  • 12. Cashing In On Cache Flushing The Page Cache <cfcacheaction=“flush” [directory="e:/temp/page_cache“]> You can use the cfcache tag with the action="flush" attribute to immediately flush one or more cached pages. You can optionally specify the directory that contains the cached pages to be flushed and a URL pattern that identifies the pages to flush. If you do not specify a URL pattern, all pages in the directory are flushed. The URL pattern can include asterisk (*) wildcards to specify parts of the URL that can vary. If you have a ColdFusion function that updates data that you use in cached pages, that function should include a cfcache tag that flushes all pages that use the data. FLUSH!
  • 13. Cashing In On Cache Flushing The Query Cache <cfquerydatasource=“myds" name=“qGetStates" cachedWithin="#CreateTimeSpan(0,0,0,0)#"> One of the first hurdles most developers face implementing query caching is how to undo the cache. Often in testing phases one discovers the database table didn’t have all the data it needed or needs a new field (or two) ‘manager special’ but one already has a cached query and doesn’t understand why they’re always getting the same results. I know it seems obvious, but it really isn’t when you first play with query caching ;)Setting your cachedWithintimespan to nothing (0,0,0,0)flushes the cached query and immediately calls thedatabase for your precious missing data! w00t! That’s what she said!
  • 14. Cashing In On ORM Cache ORM and Caching – Session and Secondary Level Caches Cache data of a persistent object <cfcomponent persistent="true" schema="APP" table="Artists" cachename="artist" cacheuse="read-only"> Cache the association data of a persistent object <cfpropertyname="art" fieldtype="one-to-many" cfc="CArt" fkcolumn="ArtID" cachename="ArtistArts" cacheuse="read-only"> Cache query data availableArts= ORMExecuteQuery("from CArt where issold=0", {}, false, {cacheable=true, cachename="availableArtsQuery"}); See the Developing ColdFusion 9 Applications guide / ColdFusion ORM / Performance optimization / Cachingsection for full details of ORM caching techniques. Nom NomNom
  • 15. Additional Resources ORM and Caching – Session and Secondary Level Caches Optimizing ColdFusion Applications There is no blog post for ColdFusion tags to avoid!! Performance tuning ColdFusion servers We hope you enjoyed this! w00t!