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

Más contenido relacionado

La actualidad más candente

Coldfusion
ColdfusionColdfusion
Coldfusion
Ram
 

La actualidad más candente (20)

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

Similar a Cfthread Presentation

Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
benbrowning
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
10n Software, LLC
 
Web Sockets are not Just for Web Browsers
Web Sockets are not Just for Web BrowsersWeb Sockets are not Just for Web Browsers
Web Sockets are not Just for Web Browsers
cjmyers
 

Similar a Cfthread Presentation (20)

PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
Php mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjanPhp mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjan
 
php training in hyderabad
php training in hyderabadphp training in hyderabad
php training in hyderabad
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
 
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
flask.pptx
flask.pptxflask.pptx
flask.pptx
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin
 
What I did on my summer vacation (in Hursley)
What I did on my summer vacation (in Hursley)What I did on my summer vacation (in Hursley)
What I did on my summer vacation (in Hursley)
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
 
Design Without Types
Design Without TypesDesign Without Types
Design Without Types
 
Child Themes and CSS in WordPress
Child Themes and CSS in WordPressChild Themes and CSS in WordPress
Child Themes and CSS in WordPress
 
AWS-DevOps (DOP-C01) Certification Study Guide
AWS-DevOps (DOP-C01) Certification   Study GuideAWS-DevOps (DOP-C01) Certification   Study Guide
AWS-DevOps (DOP-C01) Certification Study Guide
 
Commonly used design patterns
Commonly used design patternsCommonly used design patterns
Commonly used design patterns
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014
 
Web Sockets are not Just for Web Browsers
Web Sockets are not Just for Web BrowsersWeb Sockets are not Just for Web Browsers
Web Sockets are not Just for Web Browsers
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 

Cfthread Presentation

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