SlideShare a Scribd company logo
Multithreading with <cfThread>Billy Cravens
Who am I???Billy CravensDeveloping ColdFusion apps since version 4.0Early involvement with .NETConsultant .. Hire me!!!billy@billycravens.com(713) 408-3052
Enough about me…You didn’t come to hear my shameless self-promotion
Keys to success presentationsKnow your audienceMake your presentation unique and funRelevant, useful examples
The unthreaded webRequest Server does its thing ResponseComponents, functions, AJAX, web services, flushing – still an HTTP request Wait til it’s doneSOA: wait on them
Some basic examplesSingle service call: overhead + service time
My simulated shipping service
Call to single service
Some basic examplesSingle service call: overhead + service timeMultiple service calls: overhead + service 1 time + service 2 time + service N time …..
Call to multiple services
Some basic examplesSingle service call: overhead + service timeMultiple service calls: overhead + service 1 time + service 2 time + service N time …..Each service is synchronous – wait til previous one finished
Types of threading in web appsFor our purposes, 2 types:Send a task away and leave us alonePerform multiple tasks at the same time and wait for results
Run off and leave me alone<cfthread action=“run” name=“NameOfThread”>	<!--- 	whatever code you 	want goes here 	---></cfthread>
Limitations of CFThreadDoesn’t support concept of call-backsEither the thread runs and is done when its done with no notification anywhere orParent thread must wait for all child threads to finish and take action then
Parallel threads in a pageBasic example: a single thread in a pageWhen we just call a thread without joining it to page level thread, it shoots off into never never landSo to use results of thread in page:At least one thread to executeJoin our threads togetherThread results available via threadName or cfthread structure
Run thread and get results
Caveat (Limitation?)No output! Even if you put output tagsCan access output (and other neat metadata) by cfdump’ing thread scopeProblem: CFDump will strip out HTMLSolution: just output threadName.outputEspecially if you want to CFDump inside your thread!
Multiple threadsSame process, just keep track of your thread namesPass as a list when joiningLoop over cfthread structure to access contents of eachRemember scope:Variables set inside of thread do not affect page-levelRemember to be “thread safe”! Unpredictable results when you attempt to read variables not local to threadUse attributes scope (remember custom tags?)No control over order data returnedBig question: performance enhanced?
Watch out!Other variables: can always write over the variableThreads: must always be named unique!!!!Make unique (using CreateUUID() to be safe)But… CFThread scope continues for life of requestLoop over list of thread names instead
Other limitationsNo grandparents: can only have one level of child threadsEach thread sucks up a request ??Adobe CF: Standard limited to 10 threads (regardless value set in CF Admin) – rest are queuedMust buy EnterpriseBlueDragon and Railo other limitsNot part of application error handlingError: look at threadScope.error structure
Favorite tricks: Timeout a code blockSpecify timeout to your page level threadContinues when timeout expiresLook at status to determine if child thread completed (threadName.status)Doesn’t kill child thread! Only proceeds without itKill threads in CF Admin or via action=“terminate”
ConclusionSynchronous code forces us to waitAsynchronous code lets us take advantage of more resources, enhancing performanceMust rethink how data is passed around

More Related Content

PPTX
Journey To The Front End World - Part3 - The Machine
PPTX
Java script
PPTX
How to organize the business layer in software
KEY
CakePHP - The Path to 2.0
PDF
Enterprise messaging
PDF
Conscious Decoupling - Lone Star PHP
PDF
Intro to JavaScript - Thinkful LA, June 2017
PPTX
Php Indonesia x Bliblidotcom - Architecting Scalable CSS
Journey To The Front End World - Part3 - The Machine
Java script
How to organize the business layer in software
CakePHP - The Path to 2.0
Enterprise messaging
Conscious Decoupling - Lone Star PHP
Intro to JavaScript - Thinkful LA, June 2017
Php Indonesia x Bliblidotcom - Architecting Scalable CSS

What's hot (20)

KEY
Re-imaginging CakePHP
PDF
CBDW2014 - Down the RabbitMQ hole with ColdFusion
PDF
Web Development with Delphi and React - ITDevCon 2016
PDF
Multiply like rabbits with rabbit mq
KEY
SydPHP March 2012 Meetup
PDF
A look at FastCgi & Mod_PHP architecture
PPTX
WordPress Multilingual: WordCamp Antwerp 2016
PPT
VFP & Ajax
PPTX
Website design & developemet
PPTX
Cloud Orchestration is Broken
PPTX
Kohana 3.1
PPT
Coldfusion
 
PPT
vb script
PPT
Web development basics (Part-3)
PPTX
Peeling back the Lambda layers
PDF
2019 PHP Serbia - Boosting your performance with Blackfire
PDF
Before you jump into Angular
PPT
Web development basics (Part-5)
PDF
Making CLI app in ruby
PPTX
The Power of a Video Library - WordCamp Raleigh
Re-imaginging CakePHP
CBDW2014 - Down the RabbitMQ hole with ColdFusion
Web Development with Delphi and React - ITDevCon 2016
Multiply like rabbits with rabbit mq
SydPHP March 2012 Meetup
A look at FastCgi & Mod_PHP architecture
WordPress Multilingual: WordCamp Antwerp 2016
VFP & Ajax
Website design & developemet
Cloud Orchestration is Broken
Kohana 3.1
Coldfusion
 
vb script
Web development basics (Part-3)
Peeling back the Lambda layers
2019 PHP Serbia - Boosting your performance with Blackfire
Before you jump into Angular
Web development basics (Part-5)
Making CLI app in ruby
The Power of a Video Library - WordCamp Raleigh
Ad

Similar to Cfthread Presentation (20)

PDF
All about CFThread - CFUnited 2008
PPT
Language Enhancement in ColdFusion 8 - CFUnited 2007
PDF
Developing html5 mobile applications using cold fusion 11
PPT
Sa204 W Cfmx7 Application Framework Camden
PDF
CFWheels - Pragmatic, Beautiful Code
PDF
ColdFusion 11 New Features
KEY
Coding and naming conventions
PDF
Concurrency, Parallelism And IO
PDF
Threads 2x[1]
PDF
Elegant concurrency
PDF
Concurrent Ruby Application Servers
PDF
Language Basics | Coldfusion primer | Chap-1
PPT
Language enhancement in ColdFusion 8
PPT
ColdFusion Components
PPTX
Cf Summit East 2018 Scaling ColdFusion
PPTX
Threading through InterBase, Firebird, and beyond
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
PDF
CFML Enhancements in ColdFusion 10
PDF
Multithreading development with workers
PDF
C Concurrency In Action Practical Multithreading 1st Edition Anthony Williams
All about CFThread - CFUnited 2008
Language Enhancement in ColdFusion 8 - CFUnited 2007
Developing html5 mobile applications using cold fusion 11
Sa204 W Cfmx7 Application Framework Camden
CFWheels - Pragmatic, Beautiful Code
ColdFusion 11 New Features
Coding and naming conventions
Concurrency, Parallelism And IO
Threads 2x[1]
Elegant concurrency
Concurrent Ruby Application Servers
Language Basics | Coldfusion primer | Chap-1
Language enhancement in ColdFusion 8
ColdFusion Components
Cf Summit East 2018 Scaling ColdFusion
Threading through InterBase, Firebird, and beyond
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
CFML Enhancements in ColdFusion 10
Multithreading development with workers
C Concurrency In Action Practical Multithreading 1st Edition Anthony Williams
Ad

Cfthread Presentation

  • 2. Who am I???Billy CravensDeveloping ColdFusion apps since version 4.0Early involvement with .NETConsultant .. Hire me!!!billy@billycravens.com(713) 408-3052
  • 3. Enough about me…You didn’t come to hear my shameless self-promotion
  • 4. Keys to success presentationsKnow your audienceMake your presentation unique and funRelevant, useful examples
  • 5. The unthreaded webRequest Server does its thing ResponseComponents, functions, AJAX, web services, flushing – still an HTTP request Wait til it’s doneSOA: wait on them
  • 6. Some basic examplesSingle service call: overhead + service time
  • 8. Call to single service
  • 9. Some basic examplesSingle service call: overhead + service timeMultiple service calls: overhead + service 1 time + service 2 time + service N time …..
  • 10. Call to multiple services
  • 11. Some basic examplesSingle service call: overhead + service timeMultiple service calls: overhead + service 1 time + service 2 time + service N time …..Each service is synchronous – wait til previous one finished
  • 12. Types of threading in web appsFor our purposes, 2 types:Send a task away and leave us alonePerform multiple tasks at the same time and wait for results
  • 13. Run off and leave me alone<cfthread action=“run” name=“NameOfThread”> <!--- whatever code you want goes here ---></cfthread>
  • 14. Limitations of CFThreadDoesn’t support concept of call-backsEither the thread runs and is done when its done with no notification anywhere orParent thread must wait for all child threads to finish and take action then
  • 15. Parallel threads in a pageBasic example: a single thread in a pageWhen we just call a thread without joining it to page level thread, it shoots off into never never landSo to use results of thread in page:At least one thread to executeJoin our threads togetherThread results available via threadName or cfthread structure
  • 16. Run thread and get results
  • 17. Caveat (Limitation?)No output! Even if you put output tagsCan access output (and other neat metadata) by cfdump’ing thread scopeProblem: CFDump will strip out HTMLSolution: just output threadName.outputEspecially if you want to CFDump inside your thread!
  • 18. Multiple threadsSame process, just keep track of your thread namesPass as a list when joiningLoop over cfthread structure to access contents of eachRemember scope:Variables set inside of thread do not affect page-levelRemember to be “thread safe”! Unpredictable results when you attempt to read variables not local to threadUse attributes scope (remember custom tags?)No control over order data returnedBig question: performance enhanced?
  • 19. Watch out!Other variables: can always write over the variableThreads: must always be named unique!!!!Make unique (using CreateUUID() to be safe)But… CFThread scope continues for life of requestLoop over list of thread names instead
  • 20. Other limitationsNo grandparents: can only have one level of child threadsEach thread sucks up a request ??Adobe CF: Standard limited to 10 threads (regardless value set in CF Admin) – rest are queuedMust buy EnterpriseBlueDragon and Railo other limitsNot part of application error handlingError: look at threadScope.error structure
  • 21. Favorite tricks: Timeout a code blockSpecify timeout to your page level threadContinues when timeout expiresLook at status to determine if child thread completed (threadName.status)Doesn’t kill child thread! Only proceeds without itKill threads in CF Admin or via action=“terminate”
  • 22. ConclusionSynchronous code forces us to waitAsynchronous code lets us take advantage of more resources, enhancing performanceMust rethink how data is passed around