Multithreading with <cfThread><br />Billy Cravens<br />
Who am I???<br />Billy Cravens<br />Developing ColdFusion apps since version 4.0<br />Early involvement with .NET<br />Con...
Enough about me…<br />You didn’t come to hear my shameless self-promotion<br />
Keys to success presentations<br />Know your audience<br />Make your presentation unique and fun<br />Relevant, useful exa...
The unthreaded web<br />Request Server does its thing Response<br />Components, functions, AJAX, web services, flushing ...
Some basic examples<br />Single service call: overhead + service time<br />
My simulated shipping service<br />
Call to single service<br />
Some basic examples<br />Single service call: overhead + service time<br />Multiple service calls: overhead + service 1 ti...
Call to multiple services<br />
Some basic examples<br />Single service call: overhead + service time<br />Multiple service calls: overhead + service 1 ti...
Types of threading in web apps<br />For our purposes, 2 types:<br />Send a task away and leave us alone<br />Perform multi...
Run off and leave me alone<br /><cfthread action=“run” name=“NameOfThread”>	<!--- 	whatever code you 	want goes here 	--->...
Limitations of CFThread<br />Doesn’t support concept of call-backs<br />Either the thread runs and is done when its done w...
Parallel threads in a page<br />Basic example: a single thread in a page<br />When we just call a thread without joining i...
Run thread and get results<br />
Caveat (Limitation?)<br />No output! Even if you put output tags<br />Can access output (and other neat metadata) by cfdum...
Multiple threads<br />Same process, just keep track of your thread names<br />Pass as a list when joining<br />Loop over c...
Watch out!<br />Other variables: can always write over the variable<br />Threads: must always be named unique!!!!<br />Mak...
Other limitations<br />No grandparents: can only have one level of child threads<br />Each thread sucks up a request ??<br...
Favorite tricks: Timeout a code block<br />Specify timeout to your page level thread<br />Continues when timeout expires<b...
Conclusion<br />Synchronous code forces us to wait<br />Asynchronous code lets us take advantage of more resources, enhanc...
Upcoming SlideShare
Loading in …5
×

Cfthread Presentation

1,620 views
1,505 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,620
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cfthread Presentation

  1. 1. Multithreading with <cfThread><br />Billy Cravens<br />
  2. 2. Who am I???<br />Billy Cravens<br />Developing ColdFusion apps since version 4.0<br />Early involvement with .NET<br />Consultant .. Hire me!!!<br />billy@billycravens.com<br />(713) 408-3052<br />
  3. 3. Enough about me…<br />You didn’t come to hear my shameless self-promotion<br />
  4. 4. Keys to success presentations<br />Know your audience<br />Make your presentation unique and fun<br />Relevant, useful examples<br />
  5. 5. The unthreaded web<br />Request Server does its thing Response<br />Components, functions, AJAX, web services, flushing – still an HTTP request <br />Wait til it’s done<br />SOA: wait on them<br />
  6. 6. Some basic examples<br />Single service call: overhead + service time<br />
  7. 7. My simulated shipping service<br />
  8. 8. Call to single service<br />
  9. 9. Some basic examples<br />Single service call: overhead + service time<br />Multiple service calls: overhead + service 1 time + service 2 time + service N time …..<br />
  10. 10. Call to multiple services<br />
  11. 11. Some basic examples<br />Single service call: overhead + service time<br />Multiple service calls: overhead + service 1 time + service 2 time + service N time …..<br />Each service is synchronous – wait til previous one finished<br />
  12. 12. Types of threading in web apps<br />For our purposes, 2 types:<br />Send a task away and leave us alone<br />Perform multiple tasks at the same time and wait for results<br />
  13. 13. Run off and leave me alone<br /><cfthread action=“run” name=“NameOfThread”> <!--- whatever code you want goes here ---></cfthread><br />
  14. 14. Limitations of CFThread<br />Doesn’t support concept of call-backs<br />Either the thread runs and is done when its done with no notification anywhere or<br />Parent thread must wait for all child threads to finish and take action then<br />
  15. 15. Parallel threads in a page<br />Basic example: a single thread in a page<br />When we just call a thread without joining it to page level thread, it shoots off into never never land<br />So to use results of thread in page:<br />At least one thread to execute<br />Join our threads together<br />Thread results available via threadName or cfthread structure<br />
  16. 16. Run thread and get results<br />
  17. 17. Caveat (Limitation?)<br />No output! Even if you put output tags<br />Can access output (and other neat metadata) by cfdump’ing thread scope<br />Problem: CFDump will strip out HTML<br />Solution: just output threadName.output<br />Especially if you want to CFDump inside your thread!<br />
  18. 18. Multiple threads<br />Same process, just keep track of your thread names<br />Pass as a list when joining<br />Loop over cfthread structure to access contents of each<br />Remember scope:<br />Variables set inside of thread do not affect page-level<br />Remember to be “thread safe”! Unpredictable results when you attempt to read variables not local to thread<br />Use attributes scope (remember custom tags?)<br />No control over order data returned<br />Big question: performance enhanced?<br />
  19. 19. Watch out!<br />Other variables: can always write over the variable<br />Threads: must always be named unique!!!!<br />Make unique (using CreateUUID() to be safe)<br />But… CFThread scope continues for life of request<br />Loop over list of thread names instead<br />
  20. 20. Other limitations<br />No grandparents: can only have one level of child threads<br />Each thread sucks up a request ??<br />Adobe CF: Standard limited to 10 threads (regardless value set in CF Admin) – rest are queued<br />Must buy Enterprise<br />BlueDragon and Railo other limits<br />Not part of application error handling<br />Error: look at threadScope.error structure<br />
  21. 21. Favorite tricks: Timeout a code block<br />Specify timeout to your page level thread<br />Continues when timeout expires<br />Look at status to determine if child thread completed (threadName.status)<br />Doesn’t kill child thread! Only proceeds without it<br />Kill threads in CF Admin or via action=“terminate”<br />
  22. 22. Conclusion<br />Synchronous code forces us to wait<br />Asynchronous code lets us take advantage of more resources, enhancing performance<br />Must rethink how data is passed around<br />

×