Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sarge Sr. Technical Support Engineer Adobe Systems

Similar presentations


Presentation on theme: "Sarge Sr. Technical Support Engineer Adobe Systems"— Presentation transcript:

1 Sarge Sr. Technical Support Engineer Adobe Systems
Building High-performing Applications using Asynchronous Gateways - 201 Sarge Sr. Technical Support Engineer Adobe Systems CFUNITED – The premier ColdFusion conference

2 Introduction Sarge (sarge@adobe.com)
“The Man, The Myth, The Legend” Native Son Started with Allaire in March 2000 Allaire Consulting Macromedia Product Support Currently Adobe Gold Support CF Experience Started with 2.0 Build global CF site for integration with DOD PKI Contributed to a couple books and magazines June 28th – July 1st 2006

3 Agenda What’s covered (and what’s not) What is Asynchrony?
Event Gateway Primer CF Asynchronous Gateway Examples Damon Cooper’s Threading Case Studies June 28th – July 1st 2006

4 What’s Covered (and what’s not)
Asynchronous programming in CF CF Event Gateway Primer CF Asynchronous gateway Not Covered Ajax, CFAjax, etc. Flex, Flash Remoting, etc. .NET Asynchronous Programming Models June 28th – July 1st 2006

5 What is Asynchrony? State of being unsynchronized
Non-blocking, parallel requests Requests run simultaneously “Concurrent multi-tasking” June 28th – July 1st 2006

6 What is Asynchrony? (cont’d)
Benefits: Increased application response Does not always mean “no refresh” Performing multiple tasks within the same interface Better scaling applications Drawback: Programming shift Gets away from traditional request/response paradigm Requires additional threads Not suitable for all occasions/circumstances June 28th – July 1st 2006

7 Asynchronous Programming
Most applications are synchronous Procedural and object oriented designs Multiple tasks are performed sequentially Each task has to wait for running task to complete Easier to maintain state/connection Tasks can provide feedback within the request Asynchronous applications can perform multiple tasks within a single request, concurrently Tasks are performed in parallel Tasks are autonomous Asynchronous tasks may provide feedback to originating requests June 28th – July 1st 2006

8 Synchronous Example: threadsynch_serial.cfm
Damon Cooper’s code that creates 100 copies of a file Loops over <cffile> Includes 200ms sleep time Demonstrates typical synchronous application logic Multiple tasks in single template request Tasks execute/complete sequentially ~26 sec execution time June 28th – July 1st 2006

9 Sandals.com: Asynchronous Lookups
Travel site featuring Sandals resort + travel booking Internal web service (CF) for air and land travel availability Synchronous Model User submits form CF calls land web service (~4 secs) then calls air web service (~12-20 secs) Typically +30 secs avg response time Simultaneous Request hog! Asynchronous Model User submits form Java polling services (5 secs) queries both land and air web services and saves results as WDDX in single DB row ~15 sec total response time Separating functionality increases stability and responsiveness June 28th – July 1st 2006

10 Event Gateway Primer Available with ColdFusion MX 7 Enterprise (and Developer*) Allows non-HTTP communication with CF Written in Java Extensible API Ships with several types Asynchronous CFML, SMS, SAMETIME, and XMPP Example types: Directory Watcher, JMS, TCP Sockets, etc. Third-party gateways available (e.g. June 28th – July 1st 2006

11 Event Gateway Primer (cont’d)
Configurable via CF Administrator Register gateway types Start and stop gateway instances Configure thread and queue sizes June 28th – July 1st 2006

12 Event Gateway Primer (cont’d)
CF Event Gateway Architecture Event Gateway Subsystem Threads, queue, logging, etc. Configuration files Listener CFCs All the power of ColdFusion Components Specific methods for gateway types – e.g. onIncomingMessage, onAddBuddyRequest CFEvent structure Properties: gatewayID, data, originator, gatewayType Application types: Initiator/Generator Responder June 28th – July 1st 2006

13 Event Gateway Architecture
Message Generator/Receiver SMSC Server IM Provider Etc. Listener CFC CF Event Gateway Services Event CFEvent CFEvent Listener CFC or CFM Page Event CFEvent Message <CFML> June 28th – July 1st 2006

14 CFUNITED: Event Gateway Sessions
Event Gateways in CFMX 7 – Jeff Tapper June 28th – July 1st 2006

15 Asynchronous CFML Gateway
CF Event Gateway type that provides asynchronous calls to CFC methods Allows your code to call CFC methods and continue processing without waiting for them to complete or return (data/error) Useful for tasks not requiring user interaction Batch processing ( ers, site maintenance, report generation, etc.) Logging Verity Indexing (be very careful) Can be combined with any other Gateway type Provides flexibility and fosters innovation Does not return feedback to calling thread sendGatewayMessage() actually returns a queued status message – True | False See Sean Corfield’s blog posting on Concurrency: June 28th – July 1st 2006

16 Calling the Asynch CFML Gateway
Create CFC with onIncomingMessage method Required: CFEvent argument that accepts a struct Register CFC as a CFML gateway type Provide a unique ID, the path to the CFC, and a startup mode. Configuration file is not needed Start the gateway instance Remember to do this step! June 28th – July 1st 2006

17 Calling the Asynch CFML Gateway
Code CFML to call the gateway instance Use sendGatewayMessage(gatewayID, data) to pass message structure to the CFC’s CFEvent argument gatewayID – Gateway ID registered in CF Admin data – structure containing the message Optional fields in data structure: cfcpath, method, originatorID, and timeout June 28th – July 1st 2006

18 Asynchronous Example: threadsynch.cfm
Damon Cooper’s code that creates 100 copies of a file Loops over sendGatewayMessage() call doWork.cfc does the file copy Includes 200ms sleep time Demonstrates power of asynchronous programming Multiple tasks in single template request Tasks execute/complete in parallel Processing returns to requested template while tasks complete Tasks queue while waiting for available thread to run ~2sec execution time June 28th – July 1st 2006

19 Asynch CFML vs. Scheduled Tasks
Asynchronous CFML Called via CF Event Gateway Utilizes CF Event Gateway thread pool Requires sendGatewayMessage() Does not provide user feedback Hard to debug Use <cflog> and eventgateway.log Truly asynchronous Returns processing to running template Scheduled Tasks Schedule in CF Admin or CFML Uses Simultaneous Requests Requires no user interaction Does not provide user feedback Easier to debug Can fire Asynch CFML calls Pseudo-asynchronous June 28th – July 1st 2006

20 Interactive Sites: Batch Processing
Builds premier sites for hotel industry (e.g. The Golden Nugget) HotelBook.com Features advanced caching mechanism to increase responsiveness Custom API for generating/populating cache of hotels Synchronous Model Loop over individual hotels adding properties to cache Single hotel per iteration Verifies hotel’s existence in cache Single request thread model typically taking +6 hours on live site Asynchronous Model Uses CF Asynch Gateway to simultaneously cache multiple hotels Typically takes 45 minutes on live site Decreased available Event Gateway Threads for stability June 28th – July 1st 2006

21 Sports MatchMaker: Logging
SportsMatchmaker.org (in Beta) Premier sports match making site Converted from CF 5.0 to CFMX 7/Flex 2 Synchronous Model Error messages logged to file using cffile and to DB Uses custom IM and system to notify admins Can quickly lock up site if underlying systems fail (file system, , DB, etc.) Asynchronous Model Uses sendGatewayMessage() to send cfcatch struct Now uses structured error handling – including <cflog> Integrates with other Event Gateway types for admin notification (e.g. XMPP and er) June 28th – July 1st 2006

22 Asynchronous Programming: Advantages/Disadvantages
Allows tasks to run concurrently within a single request Tasks run autonomously Long running requests no longer cause increased response times Disadvantages Not suitable for all applications High user interactivity Security models Hard to debug Overuse can cause server bottleneck June 28th – July 1st 2006

23 Resources Tom Jordahl Damon Cooper
Taking Advantage of ColdFusion MX 7 Event Gateways Writing and Using Event Gateways in ColdFusion MX 7 Damon Cooper Matt Woodward ( “The Asynchronous CFML Gateway” LiveDocs: Thanks to Sandles, Interactive Sites, and SMM June 28th – July 1st 2006

24 June 28th – July 1st 2006


Download ppt "Sarge Sr. Technical Support Engineer Adobe Systems"

Similar presentations


Ads by Google