Presentation is loading. Please wait.

Presentation is loading. Please wait.

ColdFusion Performance Tuning Keen Haynes Certified ColdFusion Developer.

Similar presentations


Presentation on theme: "ColdFusion Performance Tuning Keen Haynes Certified ColdFusion Developer."— Presentation transcript:

1 ColdFusion Performance Tuning Keen Haynes Certified ColdFusion Developer

2 Overview  Application Environments  Testing Techniques  Tuning Techniques  Coding Tips  Variable Locking  Databases and Queries  Thread Processing  Debugging

3 Application Environment  Goals Provide separate, autonomous areas for Development, Testing/Staging and Production Provide the Developer Community with an environment that maximizes  Productivity  Effectiveness

4 Application Environment, cont. Provide a Testing/Staging environment that facilitates  Automated application staging  Testing  Load/Scalability testing  Production readiness (data migration, etc) Provide a Production environment that is  Scalable  Manageable  Makes efficient use of resources  Designed for High-Availability and end-user responsiveness

5 Testing Techniques  Perform “Critical Path” or “Strategic Strike” Analysis  Stress User vs. Real User  Build a “Real-World” load generator test script  Load Test & Perform Bottleneck Analysis  Do Manual Timings in a browser (no load vs under load)  Perform Endurance Testing  Examine log files during testing

6 Testing Techniques, cont.  Principle elements involved in template response time: Total Execution Time (i.e. 203ms) Query Time (i.e. 156ms) Processing/Response Time: Total - Query (i.e. 46ms)

7 Tuning Techniques  Establish your max user base line  Manually walk through test and capture explode bench marking – identify bottlenecks  Test with new general CF admin settings  Test with changes to simultaneous request settings changes – normally the biggest bang for your buck.

8 Managing Performance, cont.  Query Time: Can be significantly reduced by proper DB Design, Configuration, Tuning and Administration Use a professional Database Administrator (DBA) Ensure/verify updated/proper version of ODBC (i.e. MDAC v 2.6) and/or DB client libraries on CF Server In CF Server, try “Maintain DB Connections” (Very) generally, queries taking longer than > 150ms execution time w/no load MUST be examined closely

9 Coding Tips  Use CF built-in functions wherever possible  Avoid complex logic inside CFQUERY (build outside)  Fully scope variables  Lock all Session, Application, and Server variable access  MDAC update ComCheck  Overuse of #

10 Coding Tips  Carefully load test and analyze CFX calls response times C++, Java  Be careful using CFHTTP, CFFTP  Scalability of CFFILE  CFMAIL in mass mailings  Avoid redundant queries and looping queries  Use Stored Procedures where appropriate  Avoid redundant code Use of CFINCLUDE versus Custom Tags  Blank space

11 Coding Tips  Caching strategies Queries  Administrator  CACHEDWITHIN  Selection of content Templates  Administrator  CFCACHE  SUPERCACHE

12 Variable Locking  Server, Application, and Session vars must be locked using !  Or random memory corruption occurs.  Consider Client and Request scopes  Symptoms: PCode errors, Unknown Exception errors  Use “Full Checking” in Dev and Staging environments

13 Variable Locking Levels: Exclusive, ReadOnly  Exclusive: does not allow any operations on a given variable scope until the current process within the lock is complete.  ReadOnly: allows multiple reads within the scope but no write access.  If an Exclusive lock is processed at the same time as a ReadOnly lock, the ReadOnly lock will wait for the Exclusive lock to finish before proceeding.

14 Variable Locking Locking methods  As a general rule of practice locking should be done in the code using CFLOCK.  ReadOnly locking can be applied globally to SERVER, APPLICATION, and SESSION variables using the "Automatic Read Locking" option on the Locking page of the ColdFusion Administrator.  There is no method to write-lock variables globally in the CF Administrator when using multi-threaded sessions. One could single-thread sessions using the "Single Threaded Sessions" option, thereby eliminating the need for locking SESSION variables, but this results in severe performance degradation and is not recommended for scalable applications.

15 Variable Locking CFLOCK Syntax  Typical usage   [process] 

16 Variable Locking NAME Locks  May be used in place of locking by scope.  The NAME argument is used in place of the SCOPE argument. Nesting Locks  As a general rule of thumb, nested locks should be avoided as they can result in deadlocks. Please refer to the CFML Language Reference Documentation if nested locks are considered absolutely necessary. Avoid use of locks in queries

17 Database Issues  Use latest stable release  Look for PCode errors including “SQL” or “Query”  Queries that never return; apparent CF Server hang  Troubleshoot by setting max DB connections to 1

18 SQL  Ensure appropriate indexes are available for all common queries  Clustered Indexes in SQL Server  Avoid calling queries in loops  Use joins instead of looping around queries if possible

19 Query Caching  Appropriate for queries with few permutations  Limits to number and size of queries  No easy way to “flush” cached queries  Caching for only one minute at 10 queries per second reduces load on the database (for that query) by 600x

20 Query Caching  Example: Cache statecodes query for 10 minutes: SELECT * FROM States ORDER BY StateCode

21  A.cfm page is requested by a web browser  The.cfm request passed to the CF Web server stub  The stub sends the request to the ColdFusion Application Server for processing. Thread Processing

22 Thread Processing (cont)  A listener thread receives the request, sends it to one of the waiting active simultaneous threads to process the request. If all of simultaneous threads are busy, the listener thread places the request on a waiting list. When one of the simultaneous request slots becomes available, listener thread sends the waiting request to the active slot.

23 Thread Processing (cont)  The ColdFusion server Processes all of the CFML tags in the page Converts the results to HTML and sends them back to the web server to be sent to the browser.

24 Thread Processing (cont)  The thread is put back into the active pool to be reused. Much less resource intensive than the thread create/destroy scenario.

25 3rd Party Calls  If 3rd party call never returns a result set or error message, thread will continue to wait and will NOT timeout If many.cfm page requests with blocking third party requests  Simultaneous Request limit will be reached  ColdFusion server will appear to hang BUT: ColdFusion is not failing to process, it simply is waiting for a response from a third party resource call.

26 ColdFusion Debugging  Performance or stability problems more often than not are caused by processing of a third party request Pinpointing these third party problems can be difficult The following steps should be taken to help determine the source of the issue

27 ColdFusion Debugging  STEP 1 Examine logs

28 ColdFusion Debugging  STEP 2 Verify the source of the unresponsiveness of the ColdFusion server  Try opening up ColdFusion Administrator or other simple.CFM page  If this fails, try to open a.html or.html page  If web server returns the.html page, the web server is functioning properly, go to Step 2  If.html page does not return, web server is causing the problem, stop and restart the web server  If after stopping and starting the web server ColdFusion pages still do not return, go to step 2.

29 ColdFusion Debugging  STEP 3 Open up the NT Performance Monitor or run cfstat and add the CF "Queued Requests", and "Running Requests" counters, along with %CPU usage for the CFSERVER instance.  If third party request is suspected, at time of the hang: %CPU usage will be approx. zero, Running Requests will be approx. at Simultaneous Request limit and Queued Requests should be rising

30 ColdFusion Debugging  STEP 4 - At the time of the unresponsive period, try running a query through MSQuery using SQLPlus or ISQL. These do not connect to the database through ODBC and will verify the ODBC connection to the database Run the same SQL statement that you believe is causing the problem SQL Profiler Deadlocking

31 ColdFusion Debugging  STEP 5 - Turn on "logging of slow pages" in the debugger section. At the very least it will list the templates that are active for n seconds. This will give your users a place to start looking for long running queries

32 ColdFusion Debugging  STEP 6 - Non-functioning, or slow functioning CFX tags, or CFML code called in your ColdFusion templates can also be the cause of ColdFusion performance/stability issues. Determining that a CFX tag or piece of CFML code is causing the problem is not an easy task Use the CF function GetTickCount() around CFX tag call (or any suspected piece of slow performing code)

33 ColdFusion Debugging  Example: (code to be timed here...) Time to Complete: #totalTime#

34 ColdFusion Debugging  Versions: Be certain all patch revisions are current  OS  Kernal  C++  DB  WWW  CFAS

35 ColdFusion Debugging  Poorly written SQL statements Full table scans (not, like)  No database indexing  No use of stored procedures  Deadlocking

36 ColdFusion Debugging  CFMAIL as mass-mailer  CFX tags that lose thread control  CFHTTP - incorrect URLs  No CFLOCK around client, application variables  Poorly written logic  Liberal use of CFLOCATION  Disk I/O

37 ColdFusion Debugging  Logs Overuse (CFAS) Fill disk (DB, WWW, CFAS)  Client variable storage in registry  Debug settings on IP specific  Third party application servers sharing box  Extraneous services ScreenSaver, etc.


Download ppt "ColdFusion Performance Tuning Keen Haynes Certified ColdFusion Developer."

Similar presentations


Ads by Google