SlideShare a Scribd company logo
Gearman 'The manager' ” since it dispatches jobs to be done,  but does not do anything useful itself.”
Presentation done using info from... http://www.slideshare.net/pcdinh/gearman-and-asynchronous-processing-in-php-applications-6135047 http://assets.en.oreilly.com/1/event/45/The%20Gearman%20Cookbook%20Presentation.pdf http://www.gearman.org http://nz.php.net/manual/en/book.gearman.php others...
Scalable Solutions.. More Hardware Caching Precalculated Data Load Balancing Multi-tier application Job Queue
History Created by Danga Interactive. Some company that developed Memcache. Original implementation in perl (2005). 2008 rewriteen in C by Brian Aker PHP Extension by James Luedke
Used by Digg: 45+ Servers, 400K jobs/day Yahoo: 60+ servers, 6M jobs/day And many others..
Installing Compiling: tar xzf gearmand-X.Y.tar.gz cd gearmand-X.Y ./configure make make install Starting server: $ gearmand -d Pecl extension: tar xzf gearman-X.Y.tgz cd gearman-X.Y phpize ./configure make make install To add to the php.ini: extension="gearman.so"
Terminology Client: Create jobs to be run and send them to a job server. Worker: Run jobs given from the job server. Job Server: Handle the job queue form clients to workers.
“ A massively distributed,  massively fault tolerant  fork mechanism.” - Joe Stump, SimpleGeo Gearman is...
Open Source. Simple & Fast. Multi-language. Flexible application design. Load Balancing. No single point of failure. Features
Client Worker Job Server Job Server Client Client Client Worker Worker Worker
Memory Memcached Mysql/Drizzle PostgreSQL SQLite Tokio Cabinet Queue Options
Foreground (synchronus) Or Background (asynchronus)
Fishpond _Controller_Front::getResource('gearman') ->getGearmanClient() ->doBackground("updateCompetitorPrice", $this->_barcode); ->do("updateCompetitorPrice", $this->_barcode); GearmanClient::do() - Run a single task and return a result GearmanClient::doLow() - Run a single low priority task GearmanClient::doBackground() - Run a task in the background GearmanClient::doHighBackground() - Run a high priority task in the background GearmanClient::doLowBackground() - Run a low priority task in the background Gearman Client
Scatter / Gather. Map / Reduce. Asynchronus Queues. Pipeline Processing. Strategies
Scatter / Gather Price Calculation Image Resize Recomendations Product Detail Client
$client = Fishpond_Controller_Front::getResource('gearman') ->getGearmanClient(); //adding gearman tasks $client->addTask("getProductDetail", $barcode); $client->addTask("getPrice", $barcode); $client->addTask("resizeImage", serialize($barcode,100,100)); $client->addTask("getRecomendations", $barcode); //callbacks to know when this finish $client->setCompleteCallback(array($this, "complete")); //runing tasks $client->runTasks(); /** * Callback when task is complete *  */ public function complete($task) { $data =  $task->data(); }
GearmanClient::addTaskHigh() - Add a high priority task to run in parallel GearmanClient::addTaskLow() - Add a low priority task to run in parallel GearmanClient::addTaskBackground() - Add a background task to be run in parallel GearmanClient::addTaskHighBackground() - Add a high priority background task to be run in parallel GearmanClient::addTaskLowBackground() - Add a low priority background task to be run in parallel GearmanClient::runTasks() - Run a list of tasks in parallel Task Methods
GearmanClient::setDataCallback() - Callback function when there is a data packet for a task GearmanClient::setCompleteCallback() - Set a function to be called on task completion GearmanClient::setCreatedCallback() - Set a callback for when a task is queued. GearmanClient::setExceptionCallback() - Set a callback for worker exceptions. GearmanClient::setFailCallback() - Set callback for job failure. GearmanClient::setStatusCallback() - Set a callback for collecting task status. GearmanClient::setWarningCallback() - Set a callback for worker warnings. GearmanClient::setWorkloadCallback() - Set a callback for accepting incremental data updates Client Callback
Concurrent tasks with different workers. All tasks run in the time for longest running. Must have enough workers available. Scatter / Gather
Map/Reduce Client Task T Task T-0 Task T-3 Task T-2 Task T-1 Task T-00 Task T-02 Task T-01
Asynchronous Queues No everyting need inmediate procesing.. Competitor pricing. Emails. Whole price engine. Loging. Etc. Example: $gearmanClient = Fishpond_Controller_Front::getResource('gearman')->getGearmanClient(); $gearmanClient->doBackground("updateCompetitorPrice", $this->_barcode);
Loging <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/ CustomLog “| gearman -n -f looger” common  (client) </VirtualHost>
Pipeline Procesing Client Task T Output Worker Operation 3 Worker Operation 2 Worker Operation 1
Questions ?

More Related Content

KEY
Gearman and CodeIgniter
PDF
Distributed Queue System using Gearman
PDF
Faster PHP apps using Queues and Workers
PDF
Queue your work
PPTX
Distributed Applications with Perl & Gearman
PDF
Gearman and Perl
PDF
Gearman: A Job Server made for Scale
PDF
Khanh-Nguyen - Gearman - distributed process solution
Gearman and CodeIgniter
Distributed Queue System using Gearman
Faster PHP apps using Queues and Workers
Queue your work
Distributed Applications with Perl & Gearman
Gearman and Perl
Gearman: A Job Server made for Scale
Khanh-Nguyen - Gearman - distributed process solution

What's hot (20)

KEY
Gearman
PPT
Gearman and asynchronous processing in PHP applications
PPTX
Gearman, Supervisor and PHP - Job Management with Sanity!
PDF
Asynchronous Processing with Ruby on Rails (RailsConf 2008)
PDF
The Current State of Asynchronous Processing With Ruby
PDF
Mad scalability: Scaling when you are not Google
PDF
Cachopo - Scalable Stateful Services - Madrid Elixir Meetup
KEY
Work Queues
PDF
Care and feeding notes
ODP
Choosing a Web Architecture for Perl
PDF
Building Scalable Websites with Perl
PDF
Celery: The Distributed Task Queue
PPT
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
ODP
Performance Optimization of Rails Applications
PPTX
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
PDF
Rails Application Optimization Techniques & Tools
PDF
Data processing with celery and rabbit mq
PDF
Why and how Pricing Assistant migrated from Celery to RQ - Paris.py #2
PDF
Javascript TDD with Jasmine, Karma, and Gulp
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Gearman
Gearman and asynchronous processing in PHP applications
Gearman, Supervisor and PHP - Job Management with Sanity!
Asynchronous Processing with Ruby on Rails (RailsConf 2008)
The Current State of Asynchronous Processing With Ruby
Mad scalability: Scaling when you are not Google
Cachopo - Scalable Stateful Services - Madrid Elixir Meetup
Work Queues
Care and feeding notes
Choosing a Web Architecture for Perl
Building Scalable Websites with Perl
Celery: The Distributed Task Queue
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Performance Optimization of Rails Applications
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Rails Application Optimization Techniques & Tools
Data processing with celery and rabbit mq
Why and how Pricing Assistant migrated from Celery to RQ - Paris.py #2
Javascript TDD with Jasmine, Karma, and Gulp
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Ad

Viewers also liked (20)

PDF
Gearman
PPTX
Nagios Conference 2012 - Jason Cook - Nagios and Mod-Gearman
PDF
Gearinfive
PDF
German Perl Workshop 2015 - Infrastruktur als Code
PDF
Distribute the workload, PHPTek, Amsterdam, 2011
PPT
A Practical Event Driven Model
PDF
Scale like an ant, distribute the workload - DPC, Amsterdam, 2011
KEY
Scale like a pro with Gearman
PDF
MPI, Erlang and the web
PDF
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
PDF
Perl.Hacks.On.Vim
PDF
Gearman for MySQL
PPT
Candra lab gis v 1
PPTX
Home Automation with perl
PPT
PPTX
Ppt presentation of queues
PPT
Queue Data Structure
PPT
Unix Programming with Perl
PPTX
ZFConf 2012: Кеш без промахов средствами Zend Framework 2 (Евгений Шпилевский)
PPT
Data structures
Gearman
Nagios Conference 2012 - Jason Cook - Nagios and Mod-Gearman
Gearinfive
German Perl Workshop 2015 - Infrastruktur als Code
Distribute the workload, PHPTek, Amsterdam, 2011
A Practical Event Driven Model
Scale like an ant, distribute the workload - DPC, Amsterdam, 2011
Scale like a pro with Gearman
MPI, Erlang and the web
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
Perl.Hacks.On.Vim
Gearman for MySQL
Candra lab gis v 1
Home Automation with perl
Ppt presentation of queues
Queue Data Structure
Unix Programming with Perl
ZFConf 2012: Кеш без промахов средствами Zend Framework 2 (Евгений Шпилевский)
Data structures
Ad

Similar to Gearman - Job Queue (20)

PPT
Gearmanpresentation 110308165409-phpapp01
PPTX
Magento's Imagine eCommerce Conference: Do You Queue?
PPTX
Slideshare - Magento Imagine - Do You Queue
PPT
Gearman and asynchronous processing in PHP applications
PPTX
Gearman & PHP
PDF
Distributed work with Gearman
PDF
Gearman work queue in php
PDF
Gearman - Northeast PHP 2012
PPT
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
PPT
Gearmam, from the_worker's_perspective copy
PPT
Gearmam, from the_worker's_perspective copy
PDF
2015 ZendCon - Do you queue
PDF
Synchronize applications with akeneo/batch
ODP
Drupal course - batch API
PPTX
Do you queue (updated)
PPTX
Message Queues & Offline Processing with PHP
PPTX
North east user group tour
PPT
PHP CLI: A Cinderella Story
PDF
Faster Drupal sites using Queue API
KEY
Cooking a rabbit pie
Gearmanpresentation 110308165409-phpapp01
Magento's Imagine eCommerce Conference: Do You Queue?
Slideshare - Magento Imagine - Do You Queue
Gearman and asynchronous processing in PHP applications
Gearman & PHP
Distributed work with Gearman
Gearman work queue in php
Gearman - Northeast PHP 2012
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
2015 ZendCon - Do you queue
Synchronize applications with akeneo/batch
Drupal course - batch API
Do you queue (updated)
Message Queues & Offline Processing with PHP
North east user group tour
PHP CLI: A Cinderella Story
Faster Drupal sites using Queue API
Cooking a rabbit pie

Gearman - Job Queue

  • 1. Gearman 'The manager' ” since it dispatches jobs to be done, but does not do anything useful itself.”
  • 2. Presentation done using info from... http://www.slideshare.net/pcdinh/gearman-and-asynchronous-processing-in-php-applications-6135047 http://assets.en.oreilly.com/1/event/45/The%20Gearman%20Cookbook%20Presentation.pdf http://www.gearman.org http://nz.php.net/manual/en/book.gearman.php others...
  • 3. Scalable Solutions.. More Hardware Caching Precalculated Data Load Balancing Multi-tier application Job Queue
  • 4. History Created by Danga Interactive. Some company that developed Memcache. Original implementation in perl (2005). 2008 rewriteen in C by Brian Aker PHP Extension by James Luedke
  • 5. Used by Digg: 45+ Servers, 400K jobs/day Yahoo: 60+ servers, 6M jobs/day And many others..
  • 6. Installing Compiling: tar xzf gearmand-X.Y.tar.gz cd gearmand-X.Y ./configure make make install Starting server: $ gearmand -d Pecl extension: tar xzf gearman-X.Y.tgz cd gearman-X.Y phpize ./configure make make install To add to the php.ini: extension=&quot;gearman.so&quot;
  • 7. Terminology Client: Create jobs to be run and send them to a job server. Worker: Run jobs given from the job server. Job Server: Handle the job queue form clients to workers.
  • 8. “ A massively distributed, massively fault tolerant fork mechanism.” - Joe Stump, SimpleGeo Gearman is...
  • 9. Open Source. Simple & Fast. Multi-language. Flexible application design. Load Balancing. No single point of failure. Features
  • 10. Client Worker Job Server Job Server Client Client Client Worker Worker Worker
  • 11. Memory Memcached Mysql/Drizzle PostgreSQL SQLite Tokio Cabinet Queue Options
  • 12. Foreground (synchronus) Or Background (asynchronus)
  • 13. Fishpond _Controller_Front::getResource('gearman') ->getGearmanClient() ->doBackground(&quot;updateCompetitorPrice&quot;, $this->_barcode); ->do(&quot;updateCompetitorPrice&quot;, $this->_barcode); GearmanClient::do() - Run a single task and return a result GearmanClient::doLow() - Run a single low priority task GearmanClient::doBackground() - Run a task in the background GearmanClient::doHighBackground() - Run a high priority task in the background GearmanClient::doLowBackground() - Run a low priority task in the background Gearman Client
  • 14. Scatter / Gather. Map / Reduce. Asynchronus Queues. Pipeline Processing. Strategies
  • 15. Scatter / Gather Price Calculation Image Resize Recomendations Product Detail Client
  • 16. $client = Fishpond_Controller_Front::getResource('gearman') ->getGearmanClient(); //adding gearman tasks $client->addTask(&quot;getProductDetail&quot;, $barcode); $client->addTask(&quot;getPrice&quot;, $barcode); $client->addTask(&quot;resizeImage&quot;, serialize($barcode,100,100)); $client->addTask(&quot;getRecomendations&quot;, $barcode); //callbacks to know when this finish $client->setCompleteCallback(array($this, &quot;complete&quot;)); //runing tasks $client->runTasks(); /** * Callback when task is complete * */ public function complete($task) { $data = $task->data(); }
  • 17. GearmanClient::addTaskHigh() - Add a high priority task to run in parallel GearmanClient::addTaskLow() - Add a low priority task to run in parallel GearmanClient::addTaskBackground() - Add a background task to be run in parallel GearmanClient::addTaskHighBackground() - Add a high priority background task to be run in parallel GearmanClient::addTaskLowBackground() - Add a low priority background task to be run in parallel GearmanClient::runTasks() - Run a list of tasks in parallel Task Methods
  • 18. GearmanClient::setDataCallback() - Callback function when there is a data packet for a task GearmanClient::setCompleteCallback() - Set a function to be called on task completion GearmanClient::setCreatedCallback() - Set a callback for when a task is queued. GearmanClient::setExceptionCallback() - Set a callback for worker exceptions. GearmanClient::setFailCallback() - Set callback for job failure. GearmanClient::setStatusCallback() - Set a callback for collecting task status. GearmanClient::setWarningCallback() - Set a callback for worker warnings. GearmanClient::setWorkloadCallback() - Set a callback for accepting incremental data updates Client Callback
  • 19. Concurrent tasks with different workers. All tasks run in the time for longest running. Must have enough workers available. Scatter / Gather
  • 20. Map/Reduce Client Task T Task T-0 Task T-3 Task T-2 Task T-1 Task T-00 Task T-02 Task T-01
  • 21. Asynchronous Queues No everyting need inmediate procesing.. Competitor pricing. Emails. Whole price engine. Loging. Etc. Example: $gearmanClient = Fishpond_Controller_Front::getResource('gearman')->getGearmanClient(); $gearmanClient->doBackground(&quot;updateCompetitorPrice&quot;, $this->_barcode);
  • 22. Loging <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/ CustomLog “| gearman -n -f looger” common (client) </VirtualHost>
  • 23. Pipeline Procesing Client Task T Output Worker Operation 3 Worker Operation 2 Worker Operation 1