SlideShare a Scribd company logo
Advanced Track: Asynchronous  Threads Bil Corry lasso.pro
What Are Async Threads? Code that executes in parallel to the currently processing page.
Why Use Async Threads? Off-load tasks Improve response time to enduser by off-loading tasks that do not need to provide immediate feedback to the enduser Recurring events Lasso Scheduled Events, Email Queue, etc all are async threads. Network-hooked services lp_site_restart sets up a TCP listener that receives commands to restart Lasso
Typical Lasso Request Model Browser sends HTTP request to the web server
Web server determines the request is for Lasso and passes it to the Lasso connector
Lasso connector communicates with Lasso Server and sends the request
Lasso Server parses request, replies to Lasso connector
Lasso connector replies to web server
Web server replies to browser
Lasso Async Thread Model Lasso page initiates new thread
Just like a normal page, the thread will run until: It terminates normally
It crashes
It is terminated for taking too long
Lasso site or server is shut down When configured as such, some threads never terminate
Lasso Async Thread Model (cont) Because the request comes from Lasso itself, async threads do NOT have access to the web request info, such as client_headers, action_params, etc.
It will also not have access to the variables of the page that created it.
All file paths must be absolute from the hard disk root – [include] does not work
Lasso Async Thread Model (cont) Output from the async thread is not available, so alternative methods must be used, such as logging to a file, a database, global variable or the Lasso console
An async thread will execute according to its priority and the load on Lasso
Basic Example Async threads are surrounded by curly-braces and initiated using ->asasyn c: [{'Hello World'}->asasync] The above code doesn't show anything in the browser, but it does run asynchronously.
Sending Data to Async Thread ->asasync allows you to add params to pass into the async thread [{ var('p1') = params->find('p1')->get(1)->value } ->asasync(-params=array('p1'=1, 'p2'=2))] Can also use globals (or other shared resources), but take care to correctly send the right message to the right thread and use [thread_atomic] to keep access to the global thread-safe
Template For Copying Vars To Async Thread <?LassoScript  // from: http://www.lassotech.com/async // stuff on your page not async here... // --------------  BEGIN OF ASYNC CODE -------------- { // --------------  BEGIN OF ASYNC CODE -------------- // -------------------- //  process async! // -------------------- // // NOTE: Code below this point is processed in it's own thread! // Lasso_ExecutionTimeLimit(60 * 60); // in seconds, set this to something reasonable Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // set priority // recreate vars - this makes all the vars on the page available to the async thread iterate: params->(find:'-vars')->(get:1)->value, local:'var'; (var: #var->name) = #var->value; /iterate; // do stuff here that you want in it's own thread... // --------------  END OF ASYNC CODE -------------- }->(asasync: -params=(array: '-vars' = vars)); // --------------  END OF ASYNC CODE --------------  // do more stuff on the current page... ?>

More Related Content

PDF
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
PDF
PDF
Tuning Solr for Logs
KEY
Railsconf2011 deployment tips_for_slideshare
PPTX
PyCon Russia 2014 - Auto Scale in the Cloud
PDF
Failsafe Mechanism for Yahoo Homepage
PDF
Apache Traffic Server & Lua
PPTX
Infrastructure as Code: Introduction to Terraform
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
Tuning Solr for Logs
Railsconf2011 deployment tips_for_slideshare
PyCon Russia 2014 - Auto Scale in the Cloud
Failsafe Mechanism for Yahoo Homepage
Apache Traffic Server & Lua
Infrastructure as Code: Introduction to Terraform

What's hot (20)

PDF
Replacing Squid with ATS
PDF
Terraform 0.9 + good practices
PDF
Securing Prometheus exporters using HashiCorp Vault
PDF
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
PDF
DevOps(3) : Ansible - (MOSG)
PDF
Scaling Mapufacture on Amazon Web Services
ODP
Perl dancer
PDF
Tuning Solr & Pipeline for Logs
PDF
Configuration Management in Ansible
PDF
Getting Started with PoolParty and EC2
PDF
Top Node.js Metrics to Watch
PPTX
Creating Reusable Puppet Profiles
PPT
Triple Blitz Strike
PDF
Ansible roles done right
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
PPTX
Ansible presentation
PPTX
Using Ansible Dynamic Inventory with Amazon EC2
PDF
Infrastructure as Code with Terraform
PPT
Deploy Rails Application by Capistrano
Replacing Squid with ATS
Terraform 0.9 + good practices
Securing Prometheus exporters using HashiCorp Vault
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
DevOps(3) : Ansible - (MOSG)
Scaling Mapufacture on Amazon Web Services
Perl dancer
Tuning Solr & Pipeline for Logs
Configuration Management in Ansible
Getting Started with PoolParty and EC2
Top Node.js Metrics to Watch
Creating Reusable Puppet Profiles
Triple Blitz Strike
Ansible roles done right
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible presentation
Using Ansible Dynamic Inventory with Amazon EC2
Infrastructure as Code with Terraform
Deploy Rails Application by Capistrano
Ad

Viewers also liked (7)

PPT
интернет развитие
PPTX
Sociala Medier Och Affärsnytta - Albert Bengtson
PPS
2008 11 Berlin
PDF
Brand Management Recession
PDF
SplunkLive! London - Splunk App for Stream & MINT Breakout
PPTX
360 Fremtiden Er Her Idag
PPS
2009 02 Madagascar Images
интернет развитие
Sociala Medier Och Affärsnytta - Albert Bengtson
2008 11 Berlin
Brand Management Recession
SplunkLive! London - Splunk App for Stream & MINT Breakout
360 Fremtiden Er Her Idag
2009 02 Madagascar Images
Ad

Similar to Asynchronous Threads in Lasso 8.5 (20)

PPT
Python Deployment with Fabric
PPT
Real-Time Python Web: Gevent and Socket.io
PPTX
Deployment with Fabric
PPT
Find bottleneck and tuning in Java Application
PPT
Analysis bottleneck in J2EE application
PDF
Os Gopal
ODP
How we setup Rsync-powered Incremental Backups
PPTX
Rust Melbourne MeetUp - Rust Web Development
KEY
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
PPT
JS everywhere 2011
PDF
Systems Automation with Puppet
KEY
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
PDF
Hadoop spark performance comparison
PPT
Apache Traffic Server
PPTX
Pegasus - automate, recover, and debug scientific computations
ODP
How Xslate Works
PDF
Getting Started With Spark Structured Streaming With Dustin Vannoy | Current ...
ODP
Web program-peformance-optimization
KEY
fog or: How I Learned to Stop Worrying and Love the Cloud
PDF
About Node.js
Python Deployment with Fabric
Real-Time Python Web: Gevent and Socket.io
Deployment with Fabric
Find bottleneck and tuning in Java Application
Analysis bottleneck in J2EE application
Os Gopal
How we setup Rsync-powered Incremental Backups
Rust Melbourne MeetUp - Rust Web Development
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
JS everywhere 2011
Systems Automation with Puppet
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Hadoop spark performance comparison
Apache Traffic Server
Pegasus - automate, recover, and debug scientific computations
How Xslate Works
Getting Started With Spark Structured Streaming With Dustin Vannoy | Current ...
Web program-peformance-optimization
fog or: How I Learned to Stop Worrying and Love the Cloud
About Node.js

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx

Asynchronous Threads in Lasso 8.5

  • 1. Advanced Track: Asynchronous Threads Bil Corry lasso.pro
  • 2. What Are Async Threads? Code that executes in parallel to the currently processing page.
  • 3. Why Use Async Threads? Off-load tasks Improve response time to enduser by off-loading tasks that do not need to provide immediate feedback to the enduser Recurring events Lasso Scheduled Events, Email Queue, etc all are async threads. Network-hooked services lp_site_restart sets up a TCP listener that receives commands to restart Lasso
  • 4. Typical Lasso Request Model Browser sends HTTP request to the web server
  • 5. Web server determines the request is for Lasso and passes it to the Lasso connector
  • 6. Lasso connector communicates with Lasso Server and sends the request
  • 7. Lasso Server parses request, replies to Lasso connector
  • 8. Lasso connector replies to web server
  • 9. Web server replies to browser
  • 10. Lasso Async Thread Model Lasso page initiates new thread
  • 11. Just like a normal page, the thread will run until: It terminates normally
  • 13. It is terminated for taking too long
  • 14. Lasso site or server is shut down When configured as such, some threads never terminate
  • 15. Lasso Async Thread Model (cont) Because the request comes from Lasso itself, async threads do NOT have access to the web request info, such as client_headers, action_params, etc.
  • 16. It will also not have access to the variables of the page that created it.
  • 17. All file paths must be absolute from the hard disk root – [include] does not work
  • 18. Lasso Async Thread Model (cont) Output from the async thread is not available, so alternative methods must be used, such as logging to a file, a database, global variable or the Lasso console
  • 19. An async thread will execute according to its priority and the load on Lasso
  • 20. Basic Example Async threads are surrounded by curly-braces and initiated using ->asasyn c: [{'Hello World'}->asasync] The above code doesn't show anything in the browser, but it does run asynchronously.
  • 21. Sending Data to Async Thread ->asasync allows you to add params to pass into the async thread [{ var('p1') = params->find('p1')->get(1)->value } ->asasync(-params=array('p1'=1, 'p2'=2))] Can also use globals (or other shared resources), but take care to correctly send the right message to the right thread and use [thread_atomic] to keep access to the global thread-safe
  • 22. Template For Copying Vars To Async Thread <?LassoScript // from: http://www.lassotech.com/async // stuff on your page not async here... // -------------- BEGIN OF ASYNC CODE -------------- { // -------------- BEGIN OF ASYNC CODE -------------- // -------------------- // process async! // -------------------- // // NOTE: Code below this point is processed in it's own thread! // Lasso_ExecutionTimeLimit(60 * 60); // in seconds, set this to something reasonable Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // set priority // recreate vars - this makes all the vars on the page available to the async thread iterate: params->(find:'-vars')->(get:1)->value, local:'var'; (var: #var->name) = #var->value; /iterate; // do stuff here that you want in it's own thread... // -------------- END OF ASYNC CODE -------------- }->(asasync: -params=(array: '-vars' = vars)); // -------------- END OF ASYNC CODE -------------- // do more stuff on the current page... ?>
  • 23. Creating Context To create context within async threads, use variables to store the context of the current page (such as client_headers, file path, action_params) and use the template to pass the context into the async thread.
  • 24. Two Important Settings [Lasso_ExecutionTimeLimit] Specifies the maximum number of seconds to let this thread run. Setting it to zero will allow the thread to run continuously [Thread_SetPriority] Can set to high or low, setting it to low (Thread_Priority_Low) gives more priority to enduser requests
  • 25. Off-Loading Tasks Improve the response time to the enduser by off-loading tasks on the page that meet the following criteria: Code for task is relatively self-contained
  • 26. Task does not need to return data for the enduser to view
  • 27. Task does not have to be finished by the time the concurrent page is served
  • 28. Example of Off-Loading a Task Page originally created related records and made the enduser wait: [ loop(500); // create related record inline(-sql=”INSERT INTO mytable (id,this,that)\ VALUES (”+integer($userid)+”,”+integer($this)+”,”+integer($that)+”)”); /loop; 'Thanks for waiting!'; ]
  • 29. Example of Off-Loading a Task (cont) Page now off-loads the related records creation and response much quicker to the enduser: <?LassoScript // from: http://www.lassotech.com/async // -------------- BEGIN OF ASYNC CODE -------------- { // -------------- BEGIN OF ASYNC CODE -------------- Lasso_ExecutionTimeLimit(60 * 60); // in seconds, set this to something reasonable Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // set priority // recreate vars - this makes all the vars on the page available to the async thread iterate: params->(find:'-vars')->(get:1)->value, local:'var'; (var: #var->name) = #var->value; /iterate; loop(500); // create related record inline(-sql=”INSERT INTO mytable (id,this,that)\ VALUES (”+integer($userid)+”,”+integer($this)+”,”+integer($that)+”)”); /loop; // -------------- END OF ASYNC CODE -------------- }->(asasync: -params=(array: '-vars' = vars)); // -------------- END OF ASYNC CODE -------------- 'Thanks for waiting!'; ?>
  • 30. Creating a Recurring Event Use [while(true)] to create a continuous thread
  • 31. Use [Lasso_ExecutionTimeLimit(0)] to permit the thread to run continuously
  • 32. Can use a global to use as a switch to shut down the thread – [while(global('on'))] – just be sure to use [thread_atomic] to make it thread-safe
  • 33. Use [sleep] to pause the event between runs Very important! If the thread doesn't sleep, it will consume Lasso and the processor
  • 34. Example of a Recurring Event Creating a thread to watch a folder for new files to process: [{ Lasso_ExecutionTimeLimit(0); // run forever Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // low priority while(true); iterate(file_listdirectory('///path/from/disk/root/'),local('file')); // do something with #file /iterate; Sleep(1000*60*10); // sleep 10 minutes (in milliseconds) /while; }->asasync] This would be placed in your LassoStartup folder.
  • 35. Debugging Async threads are tricky to debug because they do not directly output the browser. Test async code outside of ->asasync
  • 37. Send debug messages to an external source (file, database, etc.)
  • 38. Test Outside of Async Easiest testing method, comment out the ->asasync container and try running your code, does it work? For recurring event threads, you'll have to limit the number of loop_counts and shorten the sleep: [//{ Lasso_ExecutionTimeLimit(0); // run forever Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // low priority while(true); loop_count > 10 ? loop_abort; iterate(file_listdirectory('///path/from/disk/root/'),local('file')); // do something with #file /iterate; Sleep(1000*60*2); // sleep 2 minutes (in milliseconds) /while; //}->asasync ]
  • 39. Trapping for Errors Place async code within [protect] to log errors: [{ Lasso_ExecutionTimeLimit(0); // run forever Thread_SetPriority(Thread_GetCurrentID, Thread_Priority_Low); // low priority protect; handle_error; log_critical('Folder watcher encounter an error: '+error_msg); /handle_error; while(true); iterate(file_listdirectory('///path/from/disk/root/'),local('file')); // do something with #file /iterate; Sleep(1000*60*10); // sleep 10 minutes (in milliseconds) /while; /protect; }->asasync]
  • 40. Send Debug Messages to External Source File
  • 44. Email