SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
Using Queues and
Offline Processing
David Stockton
Madison PHP - Oct 1, 2016
Synchronous
Processing
Shopping Trip
Car Wash
DMV
The Web Should
Be Fast
Customers Want It
To Be Fast
Think Work Order
Asynchronous
Processing
Real-World
Async
Online Shopping
Personal
Assistants
Personal
Assistants
Web Pages
Infinite Scrollers
Magical
Parallelization
Fake It
Until You Make It
Time Is
Not On Our Side
User Input
Do The Needful Now
Everything Else Can Wait
Database Queue
Data
Synchronization
Message
Queues
Work Producer
Work
Producer
How does that
help?
Workers
Workers
Multiplicity
Control Server
Load
Handle Load
Spikes
Workers as
Assistants
Ballottrax
Data Loads
Communication Rates
• Email - 250 connections, 10 per seco
• SMS - 30 per second
• Voice - 1 per second, per phone
number
Splitting Work By
Type
Rate Limiting
Queues to
Queue Work
Acceptable for
Work
Notification
Filters
Geocoding
Producers Consumers
DB Queue vs
Pure MQ
Feeding Queue from
Database - Cron
Feeding Queues from
Database - Polling
Polling -
The Worst
Events and
Webhooks
Magical
Webhooks
Automated Pull
Requests
Queues For
Webhooks
Install AMQPLib
composer require php-amqplib/
php-amqplib
Create Queue/Channel
$connection = new PhpAmqpLibConnection
AMQPStreamConnection($server, $port, $user,
$password, $vhost);

$channel = $connection->channel();

$channel->queue_declare(

$queueName,

false, // Passive

true, // Durable

false, // Exclusive

false // Auto Delete

);
Setting Channel Options
$channel->basic_qos(null, 1, null);

$channel->basic_consume(

$queueName,

'', // Consumer tag

false, // No local

false, // No ACK

false, // Exclusive

false, // No wait

$callback

);
Do Some Work


while (count($channel->callbacks)) {

$channel->wait();

}



$channel->close();

$connection->close();
The Callback
$callback = function ($msg) {

$message = (array) json_decode($msg-
>body, false);

// Do work



$msg->delivery_info['channel']
->basic_ack(

$msg->delivery_info['delivery_tag']

);

};
Creating a Message
$message = new PhpAmqpLibMessageAMQPMessage(

json_encode($data),

[

'delivery_mode' =>

AMQPMessage::DELIVERY_MODE_PERSISTENT

]

);
Putting Message in the Queue
try {

$channel->basic_publish($message, '',
$queueName);

} catch (AMQPExceptionInterface $e) {

$this->getLogger()->err(
'Error putting message into RabbitMQ',
$e->getMessage()
);

return false;

}
Work Priority
Recap
Questions?
David Stockton
@dstockto
https://davidstockton.com
https://tddftw.com

Contenu connexe

En vedette

En vedette (15)

5 Must Have Business Collaboration Tools For SEM's
5 Must Have Business Collaboration Tools For SEM's5 Must Have Business Collaboration Tools For SEM's
5 Must Have Business Collaboration Tools For SEM's
 
technologos it security
technologos it securitytechnologos it security
technologos it security
 
Around a Few Big Buttons
Around a Few Big Buttons Around a Few Big Buttons
Around a Few Big Buttons
 
1122 capacity building attitudes and behavior as rescuer 1122
1122 capacity building attitudes and behavior as rescuer 11221122 capacity building attitudes and behavior as rescuer 1122
1122 capacity building attitudes and behavior as rescuer 1122
 
Julene Helean Resume
Julene Helean ResumeJulene Helean Resume
Julene Helean Resume
 
Datanyze Overview
Datanyze OverviewDatanyze Overview
Datanyze Overview
 
How NOT to write in Node.js
How NOT to write in Node.jsHow NOT to write in Node.js
How NOT to write in Node.js
 
20160131 lr retrospecto la rinconada domingo 31/01/2016
20160131 lr retrospecto la rinconada domingo 31/01/201620160131 lr retrospecto la rinconada domingo 31/01/2016
20160131 lr retrospecto la rinconada domingo 31/01/2016
 
Itec ders planı
Itec ders planıItec ders planı
Itec ders planı
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
 
Nuclear fission
Nuclear fission Nuclear fission
Nuclear fission
 
SSMC Youth sunday 2013
SSMC Youth sunday 2013SSMC Youth sunday 2013
SSMC Youth sunday 2013
 
Customer Centricity - Center point of every company's strategy
Customer Centricity - Center point of every company's strategyCustomer Centricity - Center point of every company's strategy
Customer Centricity - Center point of every company's strategy
 
Risky Living Session Four - Luke 12
Risky Living Session Four - Luke 12Risky Living Session Four - Luke 12
Risky Living Session Four - Luke 12
 
Tale of Two Men
Tale of Two MenTale of Two Men
Tale of Two Men
 

Similaire à Using queues and offline processing to help speed up your application

Cloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptxCloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptx
terewog808
 

Similaire à Using queues and offline processing to help speed up your application (20)

Cast a wider net
Cast a wider netCast a wider net
Cast a wider net
 
Atmosphere Conference 2015: Oktawave Horizon Project: the future of real-time...
Atmosphere Conference 2015: Oktawave Horizon Project: the future of real-time...Atmosphere Conference 2015: Oktawave Horizon Project: the future of real-time...
Atmosphere Conference 2015: Oktawave Horizon Project: the future of real-time...
 
Modern Web Applications
Modern Web ApplicationsModern Web Applications
Modern Web Applications
 
Build Your Own Search Engine
Build Your Own Search EngineBuild Your Own Search Engine
Build Your Own Search Engine
 
Soa & The Next 1000 Days Of The Web
Soa & The Next 1000 Days Of The WebSoa & The Next 1000 Days Of The Web
Soa & The Next 1000 Days Of The Web
 
MS Dynamics CRM as Application Development Platform
MS Dynamics CRM as Application Development PlatformMS Dynamics CRM as Application Development Platform
MS Dynamics CRM as Application Development Platform
 
Data Streaming with Apache Kafka & MongoDB - EMEA
Data Streaming with Apache Kafka & MongoDB - EMEAData Streaming with Apache Kafka & MongoDB - EMEA
Data Streaming with Apache Kafka & MongoDB - EMEA
 
Webinar: Data Streaming with Apache Kafka & MongoDB
Webinar: Data Streaming with Apache Kafka & MongoDBWebinar: Data Streaming with Apache Kafka & MongoDB
Webinar: Data Streaming with Apache Kafka & MongoDB
 
Données animées
Données animéesDonnées animées
Données animées
 
Building prediction models with Amazon Redshift and Amazon Machine Learning -...
Building prediction models with Amazon Redshift and Amazon Machine Learning -...Building prediction models with Amazon Redshift and Amazon Machine Learning -...
Building prediction models with Amazon Redshift and Amazon Machine Learning -...
 
Openkapow At Mashup Camp 5
Openkapow At Mashup Camp 5Openkapow At Mashup Camp 5
Openkapow At Mashup Camp 5
 
Metrics, Metrics Everywhere (but where the heck do you start?)
Metrics, Metrics Everywhere (but where the heck do you start?)Metrics, Metrics Everywhere (but where the heck do you start?)
Metrics, Metrics Everywhere (but where the heck do you start?)
 
Metrics, Metrics Everywhere (but where the heck do you start?)
Metrics, Metrics Everywhere (but where the heck do you start?)Metrics, Metrics Everywhere (but where the heck do you start?)
Metrics, Metrics Everywhere (but where the heck do you start?)
 
Metrics, metrics everywhere (but where the heck do you start?)
Metrics, metrics everywhere (but where the heck do you start?)Metrics, metrics everywhere (but where the heck do you start?)
Metrics, metrics everywhere (but where the heck do you start?)
 
Real-time Communications with SignalR
Real-time Communications with SignalRReal-time Communications with SignalR
Real-time Communications with SignalR
 
Building Chatbots
Building ChatbotsBuilding Chatbots
Building Chatbots
 
Webinar: Data Streaming with Apache Kafka & MongoDB
Webinar: Data Streaming with Apache Kafka & MongoDBWebinar: Data Streaming with Apache Kafka & MongoDB
Webinar: Data Streaming with Apache Kafka & MongoDB
 
Akamai: Acelerando las aplicaciones en la nube - Miguel Serrano, Akamai
Akamai: Acelerando las aplicaciones en la nube - Miguel Serrano, AkamaiAkamai: Acelerando las aplicaciones en la nube - Miguel Serrano, Akamai
Akamai: Acelerando las aplicaciones en la nube - Miguel Serrano, Akamai
 
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
 
Cloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptxCloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptx
 

Plus de David Stockton

Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)
David Stockton
 

Plus de David Stockton (19)

Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from php
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2
 
API All the Things!
API All the Things!API All the Things!
API All the Things!
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
Common design patterns in php
Common design patterns in phpCommon design patterns in php
Common design patterns in php
 
Intermediate oop in php
Intermediate oop in phpIntermediate oop in php
Intermediate oop in php
 
Grokking regex
Grokking regexGrokking regex
Grokking regex
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)
 
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSHTame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
 
Mercurial Distributed Version Control
Mercurial Distributed Version ControlMercurial Distributed Version Control
Mercurial Distributed Version Control
 
Regular expressions and php
Regular expressions and phpRegular expressions and php
Regular expressions and php
 
PHP 5 Magic Methods
PHP 5 Magic MethodsPHP 5 Magic Methods
PHP 5 Magic Methods
 
FireBug And FirePHP
FireBug And FirePHPFireBug And FirePHP
FireBug And FirePHP
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Dernier (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Using queues and offline processing to help speed up your application