SlideShare a Scribd company logo
1 of 30
Do you queue?
Characteristics of
scalability
Kevin Schroeder
Technology Evangelist
Zend Technologies




                        © All rights reserved. Zend Technologies, Inc.
About me




Past: Programming/Sys Admin
Current: Technology Evangelist/Author/Composer
    @kpschrade

                    © All rights reserved. Zend Technologies, Inc.
I blog at eschrade.com

                         Follow us!
                  (good things will happen to you)



 Zend Technologies



 http://twitter.com/zend



 http://twitter.com/kpschrade (me!)


                      © All rights reserved. Zend Technologies, Inc.
Twtpoll results

Could your PHP apps benefit from being able to
   process data or execute asynchronously?




                  © All rights reserved. Zend Technologies, Inc.
Why would you want to queue?

• Performance
   Execute logic apart from the main request (asynchronicity)

• Scalability
   The ability to handle non-immediate logic as resources are
    available




                         © All rights reserved. Zend Technologies, Inc.
Typical anatomy of a PHP Application

                      Presentation
               Application Control


             Bad for
                 Database Access

                    Business Logic


              scala-  Presentation

               Application Control



              bility!
                    Business Logic
                      Presentation




                                                                |
               © All rights reserved. Zend Technologies, Inc.   6
Someth    Someth    Someth    Someth                                                     Someth    Someth    Someth    Someth
    ing.pht
      ml
              ing.pht
                ml
                        ing.pht
                          ml
                                  ing.pht
                                    ml               Presentation                            ing.pht
                                                                                               ml
                                                                                                       ing.pht
                                                                                                         ml
                                                                                                                 ing.pht
                                                                                                                   ml
                                                                                                                           ing.pht
                                                                                                                             ml




                                    Good for
                                              Application Control
    Someth    Someth    Someth    Someth                                                     Someth    Someth    Someth    Someth
    ing.php   ing.php   ing.php   ing.php                                                    ing.php   ing.php   ing.php   ing.php




    Someth
    ing.php
              Someth
              ing.php
                        Someth
                        ing.php
                                   Scalability
                                  Someth
                                  ing.php          Business Logic                            Someth
                                                                                             ing.php
                                                                                                       Someth
                                                                                                       ing.php
                                                                                                                 Someth
                                                                                                                 ing.php
                                                                                                                           Someth
                                                                                                                           ing.php




    Someth
    ing.php
              Someth
              ing.php
                        Someth
                        ing.php
                                  Someth
                                  ing.php        Database Access                             Someth
                                                                                             ing.php
                                                                                                       Someth
                                                                                                       ing.php
                                                                                                                 Someth
                                                                                                                 ing.php
                                                                                                                           Someth
                                                                                                                           ing.php




                                                                                                                                     |
|                                           © All rights reserved. Zend Technologies, Inc.                                           7
What helps make software scalable?



             Defined tasks
             Loose coupling
          Resource discovery



               © All rights reserved. Zend Technologies, Inc.
The Golden Rule of Scalability
   “It can probably wait”




         © All rights reserved. Zend Technologies, Inc.
Asynchronous execution uses

• Pre-caching data
• Data analysis
• Data processing
• Pre-calculating (preparing data for the next request)


   Data is “out of date” once it leaves the web server
                  Immediacy is seldom necessary




                       © All rights reserved. Zend Technologies, Inc.
Considerations

• Waste disk space
• Control usage (don’t let users do anything they want)
• Pre-calculate as much as possible
   Calculate and cache/store

• Keep data processing off the front end servers
• Don’t just cache
   Don’t let it substitute for thought

   Cache hit rates can be meaningless if you have hundreds of cache
    hits for a request



                          © All rights reserved. Zend Technologies, Inc.
Considerations

• Build a deployment mechanism with NO hardcoded values
  like directory or resource locations
 • Make as much as possible configurable/discoverable
• Decouple/Partition
   Don’t tie everything (relationships and such) into the database

• Use queues/messaging
   Stomp interfaces are really good for PHP – Can also use Java
    Bridge
   Zend_Queue has several interfaces

• Try to use stateless interfaces
   (polling is more scalable than idle connections)
                         © All rights reserved. Zend Technologies, Inc.
Options

• Use Cron /w PHP CLI (not the best idea)
   People mostly use cron simply due to availability
     • It’s an available option, not necessarily the best option.

• Use Gearman
• Use home-grown (don’t do this)
• Use pcntl_fork() (NEVER do this)
• Use Zend Server Job Queue




                            © All rights reserved. Zend Technologies, Inc.
Your only real options

Gearman*                        Zend Server Job Queue
Free                            Ready to go
Lightweight                     Integrates with Event Monitoring
Open Source                     Integrates with Code Tracing
(mostly) language               Runs over a widely known protocol
agnostic                        Load distribution can be                             Very cloud friendly
Distributed queuing             accomplished outside of the queue

           * I am not an expert on Gearman. Corrections will be taken in the spirit that they are given.




    For obvious reasons, I will focus on Zend Server

                                    © All rights reserved. Zend Technologies, Inc.
What the heck is Zend Server?
                                                        Zend Server

                    Application             Reliability &                     Scale-Out       Business-grade
                   Performance              Management                                             PHP

                    Acceleration             Monitoring                        Clustering        Hot Fixes

                    Optimization             Root-Cause                        Job Queue         Support

                       Caching              Configuration                      Downloads        Java Bridge



                                                   Zend Framework

                                                                 PHP



                          Linux                                Windows                           IBM i
                   (rpm/web repositories)                          (MSI)                         (PTF)



15   Zend Server                             © All rights reserved. Zend Technologies, Inc.
Job Queue Architecture – Elastic Backend

                               Web Server
                                                                                                Web Server
                                 /w JQ




                                                                                Load Balancer
                               Web Server
         Users!                                                                                 Web Server
                                 /w JQ

                               Web Server
                                                                                                Web Server
                                 /w JQ

• Pros
   Scale the backend as necessary

   Default (easy) mechanism

• Cons
   Getting the job status requires using a DB

                               © All rights reserved. Zend Technologies, Inc.
Job Queue Architecture – Elastic Frontend

                                                                                                    Web Server
                                   Web Server
                                                                                                      /w JQ




                                                                                    Load Balancer
                                                                                                    Web Server
         Users!                    Web Server
                                                                                                      /w JQ

                                                                                                    Web Server
                                   Web Server
                                                                                                      /w JQ


• Pros
  • Easy to communicate with the Job Queue server handling the job

Cons
  • Requires you to build your own interface (or just use mine!)



                                   © All rights reserved. Zend Technologies, Inc.
Kevin’s favorite way to implement it

• Create a task-handling controller
• Create an abstract task class
   Understands the Job Queue

   Self contained
    • If Elastic Backend: connects to localhost
    • If Elastic Frontend: connects to load balancer (my preferred), load
      balanced JQ servers manage themselves

• Execute the task, have it serialize itself and send it to send
  to the task handler




                          © All rights reserved. Zend Technologies, Inc.
Classes involved in the demo
  Manager
   Handles connecting to the queue and passing results back and forth
  JobAbstract
   Abstract class that a job would be based off of
  Response
   The response from the manager when a job is queued. Contains the
     server name and job number
  GetRemoteLinks
   • Scans a given web page and reports back a list of all the links on the
     page




                          © All rights reserved. Zend Technologies, Inc.
Execution Flow
 1.   Create job and set data
 2.   Execute job
      • Job passes itself to the queue manager
      • Manager serializes job
      • Manager uses HTTP call through a load balancer to queue the job
      • The queue on the other end returns the job id and server name
      • Job ID and server name is passed to the client
 3.   Client polls the manager to get a completed job
      • When the job is returned pass the serialized version of the executed
        job



                            © All rights reserved. Zend Technologies, Inc.
Demo


© All rights reserved. Zend Technologies, Inc.
Neato, but how in the world
does this pertain to Magento?




         © All rights reserved. Zend Technologies, Inc.
How?

• Long running front-end requests kill front-end
  responsiveness which kills the user experience
   40% will wait no more than 4 seconds for a website (Forrester)

• Calculating cache data on-the-fly can lead to bad user
  experiences (abruptly slow page load times) and
  consistency problems
• Long running page requests can push up against
  max_execution_time
   For example, handling payments from a slow CC API

   Simply setting it to run longer is a band-aid on a broken bone



                         © All rights reserved. Zend Technologies, Inc.
Solution?

1. Build Zend Server integration extensions
     Zendserver_Jobqueue
     Zendserver_Monitor
2. Utilize the event system to intercept actions
     Async_Payment (for payments, in this case)
3. Profit! (scalability AND performance, actually)




                        © All rights reserved. Zend Technologies, Inc.
Building a job

• Install the Zend Server Magento extension
• Create a class that extends
  Zendserver_Jobqueue_JobAbstract
• Call $job->execute();




                      © All rights reserved. Zend Technologies, Inc.
Payment as an example

• Hooks an observer into
  controller_action_predispatch_checkout_onepage_saveOrder, core_block_abstract_to
  _html_after

• Checks if a defined template is being rendered
• Injects JavaScript that changes the review.save() method
• Injects a new URL for submitting the transaction which
  creates a job
   Passes POSTed data to a job

• Job executes by submitting the payment URL on behalf of
  the browser, storing the result
• Browser pings the server to see if the job has completed
  executing yet
                             © All rights reserved. Zend Technologies, Inc.
Scaling the solution



             Webserver                                                        Job Queue/
                                                                               Webserver




                                                 Load Balancer
             Webserver                                                        Job Queue/
                                                                               Webserver

             Webserver                                                        Job Queue/
                                                                               Webserver

* Duplicate deployments on
ALL machines
                                         Database or
                                           Session
                                          Clustering

                             © All rights reserved. Zend Technologies, Inc.
Downloads

• Zend Server
  http://www.zend.com/server
                                                                        http://bit.ly/hWJBYw
• Zendserver_Jobqueue
  https://github.com/kschroeder/Magento-ZendServer-JobQueue

• Zendserver_Monitor
  https://github.com/kschroeder/Magento-ZendServer-Monitor

• Async_Payment
  https://github.com/kschroeder/Magento-Async-Payment

• Job Queue library & demo
  https://github.com/kschroeder/ZendServer-JobQueue-Job-API

                       © All rights reserved. Zend Technologies, Inc.
Magento/Zend Case Study - http://bit.ly/horpFF



                         Follow us!

 Zend Technologies



 http://twitter.com/zend



 http://twitter.com/kpschrade (me!)


                      © All rights reserved. Zend Technologies, Inc.
Get this information and all the
  examples at eschrade.com…




© All rights reserved. Zend Technologies, Inc.

More Related Content

More from MagentoImagine

Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...
Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...
Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...MagentoImagine
 
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...MagentoImagine
 
Magento's Imagine eCommerce Conference 2011 - eCommerce Strategy
Magento's Imagine eCommerce Conference 2011 - eCommerce StrategyMagento's Imagine eCommerce Conference 2011 - eCommerce Strategy
Magento's Imagine eCommerce Conference 2011 - eCommerce StrategyMagentoImagine
 
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...MagentoImagine
 
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...MagentoImagine
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagentoImagine
 

More from MagentoImagine (6)

Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...
Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...
Magento's Imagine eCommerce Conference 2011 - Delivering Conversion Results b...
 
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
 
Magento's Imagine eCommerce Conference 2011 - eCommerce Strategy
Magento's Imagine eCommerce Conference 2011 - eCommerce StrategyMagento's Imagine eCommerce Conference 2011 - eCommerce Strategy
Magento's Imagine eCommerce Conference 2011 - eCommerce Strategy
 
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
 
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...
Magento's Imagine eCommerce Conference 2011 - With Friends Like These, Who Ne...
 
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with MagentoMagento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
Magento's Imagine eCommerce Conference 2011 - Unit Testing with Magento
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Magento's Imagine eCommerce Conference 2011 - Do You Queue?

  • 1. Do you queue? Characteristics of scalability Kevin Schroeder Technology Evangelist Zend Technologies © All rights reserved. Zend Technologies, Inc.
  • 2. About me Past: Programming/Sys Admin Current: Technology Evangelist/Author/Composer @kpschrade © All rights reserved. Zend Technologies, Inc.
  • 3. I blog at eschrade.com Follow us! (good things will happen to you)  Zend Technologies  http://twitter.com/zend  http://twitter.com/kpschrade (me!) © All rights reserved. Zend Technologies, Inc.
  • 4. Twtpoll results Could your PHP apps benefit from being able to process data or execute asynchronously? © All rights reserved. Zend Technologies, Inc.
  • 5. Why would you want to queue? • Performance  Execute logic apart from the main request (asynchronicity) • Scalability  The ability to handle non-immediate logic as resources are available © All rights reserved. Zend Technologies, Inc.
  • 6. Typical anatomy of a PHP Application Presentation Application Control Bad for Database Access Business Logic scala- Presentation Application Control bility! Business Logic Presentation | © All rights reserved. Zend Technologies, Inc. 6
  • 7. Someth Someth Someth Someth Someth Someth Someth Someth ing.pht ml ing.pht ml ing.pht ml ing.pht ml Presentation ing.pht ml ing.pht ml ing.pht ml ing.pht ml Good for Application Control Someth Someth Someth Someth Someth Someth Someth Someth ing.php ing.php ing.php ing.php ing.php ing.php ing.php ing.php Someth ing.php Someth ing.php Someth ing.php Scalability Someth ing.php Business Logic Someth ing.php Someth ing.php Someth ing.php Someth ing.php Someth ing.php Someth ing.php Someth ing.php Someth ing.php Database Access Someth ing.php Someth ing.php Someth ing.php Someth ing.php | | © All rights reserved. Zend Technologies, Inc. 7
  • 8. What helps make software scalable? Defined tasks Loose coupling Resource discovery © All rights reserved. Zend Technologies, Inc.
  • 9. The Golden Rule of Scalability “It can probably wait” © All rights reserved. Zend Technologies, Inc.
  • 10. Asynchronous execution uses • Pre-caching data • Data analysis • Data processing • Pre-calculating (preparing data for the next request) Data is “out of date” once it leaves the web server Immediacy is seldom necessary © All rights reserved. Zend Technologies, Inc.
  • 11. Considerations • Waste disk space • Control usage (don’t let users do anything they want) • Pre-calculate as much as possible  Calculate and cache/store • Keep data processing off the front end servers • Don’t just cache  Don’t let it substitute for thought  Cache hit rates can be meaningless if you have hundreds of cache hits for a request © All rights reserved. Zend Technologies, Inc.
  • 12. Considerations • Build a deployment mechanism with NO hardcoded values like directory or resource locations • Make as much as possible configurable/discoverable • Decouple/Partition  Don’t tie everything (relationships and such) into the database • Use queues/messaging  Stomp interfaces are really good for PHP – Can also use Java Bridge  Zend_Queue has several interfaces • Try to use stateless interfaces  (polling is more scalable than idle connections) © All rights reserved. Zend Technologies, Inc.
  • 13. Options • Use Cron /w PHP CLI (not the best idea)  People mostly use cron simply due to availability • It’s an available option, not necessarily the best option. • Use Gearman • Use home-grown (don’t do this) • Use pcntl_fork() (NEVER do this) • Use Zend Server Job Queue © All rights reserved. Zend Technologies, Inc.
  • 14. Your only real options Gearman* Zend Server Job Queue Free Ready to go Lightweight Integrates with Event Monitoring Open Source Integrates with Code Tracing (mostly) language Runs over a widely known protocol agnostic Load distribution can be Very cloud friendly Distributed queuing accomplished outside of the queue * I am not an expert on Gearman. Corrections will be taken in the spirit that they are given. For obvious reasons, I will focus on Zend Server © All rights reserved. Zend Technologies, Inc.
  • 15. What the heck is Zend Server? Zend Server Application Reliability & Scale-Out Business-grade Performance Management PHP Acceleration Monitoring Clustering Hot Fixes Optimization Root-Cause Job Queue Support Caching Configuration Downloads Java Bridge Zend Framework PHP Linux Windows IBM i (rpm/web repositories) (MSI) (PTF) 15 Zend Server © All rights reserved. Zend Technologies, Inc.
  • 16. Job Queue Architecture – Elastic Backend Web Server Web Server /w JQ Load Balancer Web Server Users! Web Server /w JQ Web Server Web Server /w JQ • Pros  Scale the backend as necessary  Default (easy) mechanism • Cons  Getting the job status requires using a DB © All rights reserved. Zend Technologies, Inc.
  • 17. Job Queue Architecture – Elastic Frontend Web Server Web Server /w JQ Load Balancer Web Server Users! Web Server /w JQ Web Server Web Server /w JQ • Pros • Easy to communicate with the Job Queue server handling the job Cons • Requires you to build your own interface (or just use mine!) © All rights reserved. Zend Technologies, Inc.
  • 18. Kevin’s favorite way to implement it • Create a task-handling controller • Create an abstract task class  Understands the Job Queue  Self contained • If Elastic Backend: connects to localhost • If Elastic Frontend: connects to load balancer (my preferred), load balanced JQ servers manage themselves • Execute the task, have it serialize itself and send it to send to the task handler © All rights reserved. Zend Technologies, Inc.
  • 19. Classes involved in the demo  Manager Handles connecting to the queue and passing results back and forth  JobAbstract Abstract class that a job would be based off of  Response The response from the manager when a job is queued. Contains the server name and job number  GetRemoteLinks • Scans a given web page and reports back a list of all the links on the page © All rights reserved. Zend Technologies, Inc.
  • 20. Execution Flow 1. Create job and set data 2. Execute job • Job passes itself to the queue manager • Manager serializes job • Manager uses HTTP call through a load balancer to queue the job • The queue on the other end returns the job id and server name • Job ID and server name is passed to the client 3. Client polls the manager to get a completed job • When the job is returned pass the serialized version of the executed job © All rights reserved. Zend Technologies, Inc.
  • 21. Demo © All rights reserved. Zend Technologies, Inc.
  • 22. Neato, but how in the world does this pertain to Magento? © All rights reserved. Zend Technologies, Inc.
  • 23. How? • Long running front-end requests kill front-end responsiveness which kills the user experience  40% will wait no more than 4 seconds for a website (Forrester) • Calculating cache data on-the-fly can lead to bad user experiences (abruptly slow page load times) and consistency problems • Long running page requests can push up against max_execution_time  For example, handling payments from a slow CC API  Simply setting it to run longer is a band-aid on a broken bone © All rights reserved. Zend Technologies, Inc.
  • 24. Solution? 1. Build Zend Server integration extensions  Zendserver_Jobqueue  Zendserver_Monitor 2. Utilize the event system to intercept actions  Async_Payment (for payments, in this case) 3. Profit! (scalability AND performance, actually) © All rights reserved. Zend Technologies, Inc.
  • 25. Building a job • Install the Zend Server Magento extension • Create a class that extends Zendserver_Jobqueue_JobAbstract • Call $job->execute(); © All rights reserved. Zend Technologies, Inc.
  • 26. Payment as an example • Hooks an observer into controller_action_predispatch_checkout_onepage_saveOrder, core_block_abstract_to _html_after • Checks if a defined template is being rendered • Injects JavaScript that changes the review.save() method • Injects a new URL for submitting the transaction which creates a job  Passes POSTed data to a job • Job executes by submitting the payment URL on behalf of the browser, storing the result • Browser pings the server to see if the job has completed executing yet © All rights reserved. Zend Technologies, Inc.
  • 27. Scaling the solution Webserver Job Queue/ Webserver Load Balancer Webserver Job Queue/ Webserver Webserver Job Queue/ Webserver * Duplicate deployments on ALL machines Database or Session Clustering © All rights reserved. Zend Technologies, Inc.
  • 28. Downloads • Zend Server  http://www.zend.com/server http://bit.ly/hWJBYw • Zendserver_Jobqueue  https://github.com/kschroeder/Magento-ZendServer-JobQueue • Zendserver_Monitor  https://github.com/kschroeder/Magento-ZendServer-Monitor • Async_Payment  https://github.com/kschroeder/Magento-Async-Payment • Job Queue library & demo  https://github.com/kschroeder/ZendServer-JobQueue-Job-API © All rights reserved. Zend Technologies, Inc.
  • 29. Magento/Zend Case Study - http://bit.ly/horpFF Follow us!  Zend Technologies  http://twitter.com/zend  http://twitter.com/kpschrade (me!) © All rights reserved. Zend Technologies, Inc.
  • 30. Get this information and all the examples at eschrade.com… © All rights reserved. Zend Technologies, Inc.

Editor's Notes

  1. We released Zend Server and Zend Server Community Edition in April this year Products written from scratch based on our very extensive experience with Platform technologies Full integrated stack, native installer, ZF and Studio integration, software updates, all new UI, … Both editions have been very well received by users (love performance boost, ease of use, deployment) Great fit to our partners – we’re working with Varien/Magento, KnowledgeTree, MCS, … Next step will round up web app server offering to support high availability and scalability – more on this in the next few months