SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Downloaden Sie, um offline zu lesen
Dominik Jungowski / CHIP Xonio Online GmbH


Distributed work with
Gearman
Law of two feet
Dominik Jungowski

27 years old

ScrumMaster at CHIP Online

Psychology student at Fernuni
  Hagen
Topics

What is Gearman?

Setting up Gearman

Basic Usage

Job status

Error handling

Managing workers
What is Gearman?
Script   Processing   Script (cont.)
Script   Processing   Script (cont.)
Worker




Script   Worker




         Worker
Setting up Gearman server
        latest version: 0.24
aptitude install gearman-job-server
Setting up PECL Extension
pecl install channel://pecl.php.net/gearman-0.8.0.tgz
extension=gearman.so
user@server:~# gearmand
Basic Usage
Worker
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction(
     ‘imageResize‘,
     array($image, ‘resize‘)
);

while($worker->work()) {
}
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction(
     ‘imageResize‘,
     array($image, ‘resize‘)
);

while($worker->work()) {
}
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction(
     ‘imageResize‘,
     array($image, ‘resize‘)
);

while($worker->work()) {
}
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction(
     ‘imageResize‘,
     array($image, ‘resize‘)
);

while($worker->work()) {
}
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction(
     ‘imageResize‘,
     array($image, ‘resize‘)
);

while($worker->work()) {
}
namespace Cxo;

class Image
{
     public function resize(GearmanJob $job)
     {
          $tmpFile = $job->workload();
          // Resizing takes place here
          ...
          return $finalFileName;
     }
}
namespace Cxo;

class Image
{
     public function resize(GearmanJob $job)
     {
          $tmpFile = $job->workload();
          // Resizing takes place here
          ...
          return $finalFileName;
     }
}
namespace Cxo;

class Image
{
     public function resize(GearmanJob $job)
     {
          $tmpFile = $job->workload();
          // Resizing takes place here
          ...
          return $finalFileName;
     }
}
namespace Cxo;

class Image
{
     public function resize(GearmanJob $job)
     {
          $tmpFile = $job->workload();
          // Resizing takes place here
          ...
          return $finalFileName;
     }
}
Synchronous Jobs
$client = new GearmanClient();
$client->addServer();

$client->do('imageResize', '/tmp/someimage.jpg');
$client = new GearmanClient();
$client->addServer();

$client->do('imageResize', '/tmp/someimage.jpg');
$client = new GearmanClient();
$client->addServer();

$client->do('imageResize', '/tmp/someimage.jpg');
$client = new GearmanClient();
$client->addServer();

$client->do('imageResize', '/tmp/someimage.jpg');
$client->doHigh();
$client->do() returns worker result
Asynchronous Jobs
$client->doBackground(
      'imageResize',
      '/tmp/someimage.jpg'
);
$client->doBackground() returns job handle
Tasks
$client->addTask(
      'imageResize',
      '/tmp/someimage.jpg'
);
$client->addTaskBackground(
      'imageResize',
      '/tmp/someimage.jpg'
);
$client->runTasks();
Scale by adding more workers
   (as long as you‘re not running jobs synchronously)
Script   Processing   Script (cont.)
Processing




Script   Processing   Script (cont.)




         Processing
Job status
$handle = $client->doBackground();
$status = $client->jobStatus($handle);
array(4) {
  [0]=> bool(true)   // Is the job known?
  [1]=> bool(true)   // Is the job running?
  [2]=> int(4)       // Numerator
  [3]=> int(10)      // Denominator
}
$job->sendStatus(4, 10);
Error handling
GEARMAN_SUCCESS
GEARMAN_WORK_FAIL
$worker->returnCode();
$client->returnCode();
$job->sendFail();
$job->sendWarning(‘Something went wrong‘);
$job->sendException(‘Something went wrong‘);
$message = $client->do();
Managing workers
supervisord
Memory consumption
Persistence
“Whuh?“
$client->doJobHandle();
doesn‘t do what it should - and many more functions as well
GearmanClient::setOptions

Return Values: Always returns TRUE
do is a keyword
Thank you!




joind.in: http://joind.in/3907
    Twitter: @djungowski
 Blog: www.phpdevblog.net

Weitere ähnliche Inhalte

Was ist angesagt?

Gearman bundle, Warszawa 2013 edition
Gearman bundle, Warszawa 2013 editionGearman bundle, Warszawa 2013 edition
Gearman bundle, Warszawa 2013 edition
Marc Morera
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
techmonkey4u
 
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Gosuke Miyashita
 
Real world scala
Real world scalaReal world scala
Real world scala
lunfu zhong
 

Was ist angesagt? (19)

Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job QueueTask Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
 
Ass 1
Ass 1Ass 1
Ass 1
 
Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?
 
Grailsでドメイン駆動設計を実践する時の勘所
Grailsでドメイン駆動設計を実践する時の勘所Grailsでドメイン駆動設計を実践する時の勘所
Grailsでドメイン駆動設計を実践する時の勘所
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyone
 
Gearman bundle, Warszawa 2013 edition
Gearman bundle, Warszawa 2013 editionGearman bundle, Warszawa 2013 edition
Gearman bundle, Warszawa 2013 edition
 
FunctionalJS - George Shevtsov
FunctionalJS - George ShevtsovFunctionalJS - George Shevtsov
FunctionalJS - George Shevtsov
 
Use of django at jolt online v3
Use of django at jolt online v3Use of django at jolt online v3
Use of django at jolt online v3
 
You promise?
You promise?You promise?
You promise?
 
BioMake PAG 2017
BioMake PAG 2017 BioMake PAG 2017
BioMake PAG 2017
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
 
PSGI REST API
PSGI REST APIPSGI REST API
PSGI REST API
 
Modern wx perl
Modern wx perlModern wx perl
Modern wx perl
 
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Real world scala
Real world scalaReal world scala
Real world scala
 
Do more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLIDo more, faster, by extending WP-CLI
Do more, faster, by extending WP-CLI
 

Andere mochten auch (9)

Gearman Add To Your Project
Gearman Add To Your ProjectGearman Add To Your Project
Gearman Add To Your Project
 
Gearman Introduction
Gearman IntroductionGearman Introduction
Gearman Introduction
 
MapReduce Using Perl and Gearman
MapReduce Using Perl and GearmanMapReduce Using Perl and Gearman
MapReduce Using Perl and Gearman
 
Global english
Global englishGlobal english
Global english
 
Jack Cross Tree Sculptures
Jack Cross Tree SculpturesJack Cross Tree Sculptures
Jack Cross Tree Sculptures
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solution
 
Gearman
GearmanGearman
Gearman
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
 
Hep Y Bir Thday Eva Vi Viana
Hep Y Bir Thday  Eva  Vi VianaHep Y Bir Thday  Eva  Vi Viana
Hep Y Bir Thday Eva Vi Viana
 

Ähnlich wie Distributed work with Gearman

Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
Brian Aker
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
Brian Aker
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
Albert Jessurum
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
Morgan Cheng
 

Ähnlich wie Distributed work with Gearman (20)

Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Gearman - Job Queue
Gearman - Job QueueGearman - Job Queue
Gearman - Job Queue
 
Gearman and Perl
Gearman and PerlGearman and Perl
Gearman and Perl
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
 
Code me a HR
Code me a HRCode me a HR
Code me a HR
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & Gearman
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
Loadrunner
LoadrunnerLoadrunner
Loadrunner
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Event Sourcing with php
Event Sourcing with phpEvent Sourcing with php
Event Sourcing with php
 

Mehr von Dominik Jungowski

Stolpersteine agiler Methoden
Stolpersteine agiler MethodenStolpersteine agiler Methoden
Stolpersteine agiler Methoden
Dominik Jungowski
 

Mehr von Dominik Jungowski (20)

Agil vs. $kunde
Agil vs. $kundeAgil vs. $kunde
Agil vs. $kunde
 
Definition of almost done
Definition of almost doneDefinition of almost done
Definition of almost done
 
TestDrivenDevelopment.php
TestDrivenDevelopment.phpTestDrivenDevelopment.php
TestDrivenDevelopment.php
 
Definition of almost done
Definition of almost doneDefinition of almost done
Definition of almost done
 
Definition of almost Done
Definition of almost DoneDefinition of almost Done
Definition of almost Done
 
Scrum, Kanban oder vielleicht beides?
Scrum, Kanban oder vielleicht beides?Scrum, Kanban oder vielleicht beides?
Scrum, Kanban oder vielleicht beides?
 
Schlank oder krank? Mit Lean Startup zum Erfolg
Schlank oder krank? Mit Lean Startup zum ErfolgSchlank oder krank? Mit Lean Startup zum Erfolg
Schlank oder krank? Mit Lean Startup zum Erfolg
 
Agile Fortschritte erfolgreich verhindern
Agile Fortschritte erfolgreich verhindernAgile Fortschritte erfolgreich verhindern
Agile Fortschritte erfolgreich verhindern
 
Kanban in der Softwareentwicklung
Kanban in der SoftwareentwicklungKanban in der Softwareentwicklung
Kanban in der Softwareentwicklung
 
Agile fortschritte erfolgreich verhindern
Agile fortschritte erfolgreich verhindernAgile fortschritte erfolgreich verhindern
Agile fortschritte erfolgreich verhindern
 
Von Fischen und Menschen
Von Fischen und MenschenVon Fischen und Menschen
Von Fischen und Menschen
 
Mythen und fakten über behavior driven development
Mythen und fakten über behavior driven developmentMythen und fakten über behavior driven development
Mythen und fakten über behavior driven development
 
The five dysfunctions of a team
The five dysfunctions of a teamThe five dysfunctions of a team
The five dysfunctions of a team
 
Stolpersteine agiler Methoden
Stolpersteine agiler MethodenStolpersteine agiler Methoden
Stolpersteine agiler Methoden
 
Arbeitsmethoden
ArbeitsmethodenArbeitsmethoden
Arbeitsmethoden
 
RIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JSRIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JS
 
RIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JSRIA - Entwicklung mit Ext JS
RIA - Entwicklung mit Ext JS
 
Ziele setzen und erreichen
Ziele setzen und erreichenZiele setzen und erreichen
Ziele setzen und erreichen
 
Pecha Kucha
Pecha KuchaPecha Kucha
Pecha Kucha
 
Better Quality through Scrum (2011)
Better Quality through Scrum (2011)Better Quality through Scrum (2011)
Better Quality through Scrum (2011)
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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
Safe Software
 

Kürzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+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...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

Distributed work with Gearman