SlideShare a Scribd company logo
Do you queue?By Kevin SchroederTechnology EvangelistZend Technologies
About Kevin Past: Programming/Sys Admin Current: Technology Evangelist/Author/Composer         @kpschrade
Could your PHP apps benefit from being able to process data or execute asynchronously?Twtpoll results
PerformanceExecute logic apart from the main request (asynchronicity)ScalabilityThe ability to handle non-immediate logic as resources are availableWhy would you want to queue?
People often say that performance and scalability are separate things.This is inaccurate (consider Google)Performance is the speed by which a request is executedScalability is the ability of that request to maintain its performance as load/infrastructure increasesPerformance & Scalability
DON’T!!You are not FacebookYou probably won’t beDon’t overcomplicate your problems by trying to beSo how do you scale to Facebook size?
Typical anatomy of a PHP ApplicationBad for scala-bility!PresentationApplication ControlDatabase AccessBusiness LogicPresentationApplication ControlBusiness LogicPresentation| 7
Good for ScalabilityPresentationSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlApplication ControlSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpBusiness LogicSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpDatabase AccessSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.php| 8 |   6-Jun-11
Defined tasksLoose couplingResource discoveryWhat helps make software scalable?
The Golden Rule of Scalability“It can probably wait”
Pre-caching dataData analysisPre-analysis (predicting where your users will go)Data processingPre-calculating (preparing data for the next request)Data is “out of date” once it leaves the web serverImmediacy is seldom necessaryAsynchronous execution uses
A sledgehammer can hit a machineScalability and High Availability are yin and yangA site that can’t keep running is not scalableA site that can’t scale will fail (if it gets really popular)Machines can be added and removed at willNot “cloudy” necessarilyNo single point of failureData exists in at least two, preferably at least three, placesCharacteristics
Waste disk spaceControl usage (don’t let users do anything they want)Pre-calculate as much as possibleCalculate and cache/storeDon’t scan large amounts of dataKeep data processing off the front end serversDon’t just cacheDon’t let it substitute for thoughtCache hit rates can be meaningless if you have hundreds of cache hits for a requestConsiderations
Build a deployment mechanism with NO hardcoded values like directory or resource locations
Make as much as possible configurable/discoverableDecouple/PartitionDon’t tie everything (relationships and such) into the databaseUse queues/messagingStomp interfaces are really good for PHP – Can also use Java BridgeZend_Queue has several interfacesTry to use stateless interfacespolling is more scalable than idle connections; introduces lagConsiderations
Use Cron /w PHP CLI (probably shouldn’t do this)Use GearmanUse home-grown (don’t do this)Use pcntl_fork() (NEVER do this)Use Zend Server Job QueueOptions
Your only real optionsVery cloud friendly* 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
Schedule jobs in the futureSet recurring jobsExecute immediately, as resources are available (my fav)Utilize ZendJobQueue()Using the Zend Server Job Queue
Job Queue Architecture – Elastic BackendWeb Server /w JQWeb ServerUsers!Web Server /w JQWeb ServerLoad BalancerWeb Server /w JQWeb ServerProsScale the backend as necessaryDefault (easy) mechanismConsGetting the job status requires using a DB
Job Queue Architecture – Elastic FrontendWeb ServerWeb Server /w JQUsers!Web ServerWeb Server /w JQLoad BalancerWeb ServerWeb Server /w JQProsEasy to communicate with the Job Queue server handling the jobConsRequires you to build your own interface
Create a task-handling controllerCreate an abstract task classUnderstands the Job QueueSelf containedIf Elastic Backend: connects to localhostIf Elastic Frontend: connects to load balancer (my preferred), load balanced JQ servers manage themselvesExecute the task, have it serialize itself and send it to send to the task handlerKevin’s favorite way to implement it
com\zend\jobqueue\ManagerHandles connecting to the queue and passing results back and forthcom\zend\jobqueue\JobAbstractAbstract class that a job would be based off ofcom\zend\jobqueue\ResponseThe response from the manager when a job is queued.  Contains the server name and job numberorg\eschrade\jobs\ScandirThe actual job that scans the directoryorg\eschrade\jobs\ScandirResultAn object that represents the data foundClasses involved in the demo
Create job and set dataExecute jobJob passes itself to the queue managerManager serializes jobManager uses HTTP call through a load balancer to queue the jobThe queue on the other end returns the job id and server nameJob ID and server name is passed to the clientClient polls the manager to get a completed jobWhen the job is returned pass the serialized version of the executed jobExecution Flow
Let’s write some code(no I’m not copping out with slides.  We’re all told to show our work in grade skool)
Follow us!Zend Technologieshttp://twitter.com/zendhttp://twitter.com/kpschrade (me!)

More Related Content

PPTX
Slideshare - Magento Imagine - Do You Queue
PDF
Grokking TechTalk #20: PostgreSQL Internals 101
ODP
Bigtop elancesmallrev1
PPTX
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
PPT
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF
M is for modernization
ODP
Deferred Processing in Ruby - Philly rb - August 2011
PPTX
Theme development workflow
Slideshare - Magento Imagine - Do You Queue
Grokking TechTalk #20: PostgreSQL Internals 101
Bigtop elancesmallrev1
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
M is for modernization
Deferred Processing in Ruby - Philly rb - August 2011
Theme development workflow

What's hot (20)

PPTX
Datasets, APIs, and Web Scraping
PPTX
DSL, Page Object and Selenium – a way to reliable functional tests
PPTX
Ajax Technology
PPT
PHP - Introduction to PHP AJAX
PDF
Domain Driven Rails
PDF
Ajax Introduction Presentation
PDF
Dumb and smart components + redux (1)
PPTX
Lets cook cucumber !!
PPTX
Introduction to ajax
ODP
Aspect-Oriented Programming for PHP
PPTX
Ajug april 2011
PPTX
Introduction to Test Driven Development
PDF
Gemboys
PDF
DataEngConf SF16 - Three lessons learned from building a production machine l...
PDF
HyperBatch
PPTX
Hadoop and Cascading At AJUG July 2009
PPTX
Overview of AJAX
Datasets, APIs, and Web Scraping
DSL, Page Object and Selenium – a way to reliable functional tests
Ajax Technology
PHP - Introduction to PHP AJAX
Domain Driven Rails
Ajax Introduction Presentation
Dumb and smart components + redux (1)
Lets cook cucumber !!
Introduction to ajax
Aspect-Oriented Programming for PHP
Ajug april 2011
Introduction to Test Driven Development
Gemboys
DataEngConf SF16 - Three lessons learned from building a production machine l...
HyperBatch
Hadoop and Cascading At AJUG July 2009
Overview of AJAX
Ad

Similar to Do you queue (updated) (20)

PPTX
North east user group tour
PPTX
Do you queue
PPTX
Magento's Imagine eCommerce Conference: Do You Queue?
ODP
Front Range PHP NoSQL Databases
PPT
The 90-Day Startup with Google AppEngine for Java
PPT
Intro to-html-backbone
PDF
Drupal Performance : DrupalCamp North
PPTX
Natural Laws of Software Performance
PPTX
Java Enterprise Performance - Unburdended Applications
PPT
Top 10 Scalability Mistakes
PPTX
No more Three Tier - A path to a better code for Cloud and Azure
ODP
Php Site Optimization
KEY
Architecting single-page front-end apps
PPT
scale_perf_best_practices
PPT
Apache Con 2008 Top 10 Mistakes
PPT
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
PPT
Hadoop and Voldemort @ LinkedIn
PPTX
Domain Driven Design
PPTX
ASP.NET Best Practices - Useful Tips from the Trenches
PPT
Intro to Application Express
North east user group tour
Do you queue
Magento's Imagine eCommerce Conference: Do You Queue?
Front Range PHP NoSQL Databases
The 90-Day Startup with Google AppEngine for Java
Intro to-html-backbone
Drupal Performance : DrupalCamp North
Natural Laws of Software Performance
Java Enterprise Performance - Unburdended Applications
Top 10 Scalability Mistakes
No more Three Tier - A path to a better code for Cloud and Azure
Php Site Optimization
Architecting single-page front-end apps
scale_perf_best_practices
Apache Con 2008 Top 10 Mistakes
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Hadoop and Voldemort @ LinkedIn
Domain Driven Design
ASP.NET Best Practices - Useful Tips from the Trenches
Intro to Application Express
Ad

More from 10n Software, LLC (12)

PPTX
Delaying Gratification: Using queues to build efficient systems
PPTX
PPTX
Flex and PHP For the Flash Folks
PPTX
PHP Performance: Principles and tools
PPTX
Application Deployment with Zend Server 5.5 beta
PPTX
Flex for php developers
PPTX
Creating stunning data analytics dashboard using php and flex
PPTX
Php security common 2011
PPTX
Zend Server - OSI Days
PPTX
Zend Framework Workshop
PPTX
Slides from LAX & DEN usergroup meetings
ODP
Flex and Zend Framework
Delaying Gratification: Using queues to build efficient systems
Flex and PHP For the Flash Folks
PHP Performance: Principles and tools
Application Deployment with Zend Server 5.5 beta
Flex for php developers
Creating stunning data analytics dashboard using php and flex
Php security common 2011
Zend Server - OSI Days
Zend Framework Workshop
Slides from LAX & DEN usergroup meetings
Flex and Zend Framework

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
NewMind AI Monthly Chronicles - July 2025
The AUB Centre for AI in Media Proposal.docx
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction

Do you queue (updated)

  • 1. Do you queue?By Kevin SchroederTechnology EvangelistZend Technologies
  • 2. About Kevin Past: Programming/Sys Admin Current: Technology Evangelist/Author/Composer @kpschrade
  • 3. Could your PHP apps benefit from being able to process data or execute asynchronously?Twtpoll results
  • 4. PerformanceExecute logic apart from the main request (asynchronicity)ScalabilityThe ability to handle non-immediate logic as resources are availableWhy would you want to queue?
  • 5. People often say that performance and scalability are separate things.This is inaccurate (consider Google)Performance is the speed by which a request is executedScalability is the ability of that request to maintain its performance as load/infrastructure increasesPerformance & Scalability
  • 6. DON’T!!You are not FacebookYou probably won’t beDon’t overcomplicate your problems by trying to beSo how do you scale to Facebook size?
  • 7. Typical anatomy of a PHP ApplicationBad for scala-bility!PresentationApplication ControlDatabase AccessBusiness LogicPresentationApplication ControlBusiness LogicPresentation| 7
  • 8. Good for ScalabilityPresentationSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlSomething.phtmlApplication ControlSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpBusiness LogicSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpDatabase AccessSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.phpSomething.php| 8 | 6-Jun-11
  • 9. Defined tasksLoose couplingResource discoveryWhat helps make software scalable?
  • 10. The Golden Rule of Scalability“It can probably wait”
  • 11. Pre-caching dataData analysisPre-analysis (predicting where your users will go)Data processingPre-calculating (preparing data for the next request)Data is “out of date” once it leaves the web serverImmediacy is seldom necessaryAsynchronous execution uses
  • 12. A sledgehammer can hit a machineScalability and High Availability are yin and yangA site that can’t keep running is not scalableA site that can’t scale will fail (if it gets really popular)Machines can be added and removed at willNot “cloudy” necessarilyNo single point of failureData exists in at least two, preferably at least three, placesCharacteristics
  • 13. Waste disk spaceControl usage (don’t let users do anything they want)Pre-calculate as much as possibleCalculate and cache/storeDon’t scan large amounts of dataKeep data processing off the front end serversDon’t just cacheDon’t let it substitute for thoughtCache hit rates can be meaningless if you have hundreds of cache hits for a requestConsiderations
  • 14. Build a deployment mechanism with NO hardcoded values like directory or resource locations
  • 15. Make as much as possible configurable/discoverableDecouple/PartitionDon’t tie everything (relationships and such) into the databaseUse queues/messagingStomp interfaces are really good for PHP – Can also use Java BridgeZend_Queue has several interfacesTry to use stateless interfacespolling is more scalable than idle connections; introduces lagConsiderations
  • 16. Use Cron /w PHP CLI (probably shouldn’t do this)Use GearmanUse home-grown (don’t do this)Use pcntl_fork() (NEVER do this)Use Zend Server Job QueueOptions
  • 17. Your only real optionsVery cloud friendly* 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
  • 18. Schedule jobs in the futureSet recurring jobsExecute immediately, as resources are available (my fav)Utilize ZendJobQueue()Using the Zend Server Job Queue
  • 19. Job Queue Architecture – Elastic BackendWeb Server /w JQWeb ServerUsers!Web Server /w JQWeb ServerLoad BalancerWeb Server /w JQWeb ServerProsScale the backend as necessaryDefault (easy) mechanismConsGetting the job status requires using a DB
  • 20. Job Queue Architecture – Elastic FrontendWeb ServerWeb Server /w JQUsers!Web ServerWeb Server /w JQLoad BalancerWeb ServerWeb Server /w JQProsEasy to communicate with the Job Queue server handling the jobConsRequires you to build your own interface
  • 21. Create a task-handling controllerCreate an abstract task classUnderstands the Job QueueSelf containedIf Elastic Backend: connects to localhostIf Elastic Frontend: connects to load balancer (my preferred), load balanced JQ servers manage themselvesExecute the task, have it serialize itself and send it to send to the task handlerKevin’s favorite way to implement it
  • 22. com\zend\jobqueue\ManagerHandles connecting to the queue and passing results back and forthcom\zend\jobqueue\JobAbstractAbstract class that a job would be based off ofcom\zend\jobqueue\ResponseThe response from the manager when a job is queued. Contains the server name and job numberorg\eschrade\jobs\ScandirThe actual job that scans the directoryorg\eschrade\jobs\ScandirResultAn object that represents the data foundClasses involved in the demo
  • 23. Create job and set dataExecute jobJob passes itself to the queue managerManager serializes jobManager uses HTTP call through a load balancer to queue the jobThe queue on the other end returns the job id and server nameJob ID and server name is passed to the clientClient polls the manager to get a completed jobWhen the job is returned pass the serialized version of the executed jobExecution Flow
  • 24. Let’s write some code(no I’m not copping out with slides. We’re all told to show our work in grade skool)
  • 26. Get this information and all the examples at eschrade.com…