distributed work with gearman · dominik jungowski 27 years old scrum coach at inovex gmbh...
TRANSCRIPT
![Page 1: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/1.jpg)
Distributed work with Gearman
Dominik Jungowski / inovex GmbH
![Page 2: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/2.jpg)
Law of two feet
![Page 3: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/3.jpg)
Dominik Jungowski
27 years old
Scrum Coach at inovex GmbH
Psychology student at Fernuni Hagen
![Page 4: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/4.jpg)
Topics
What is Gearman?
Setting up Gearman
Basic Usage
Job status
Error handling
Managing workers
![Page 5: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/5.jpg)
What is Gearman?
![Page 6: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/6.jpg)
![Page 7: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/7.jpg)
Script Processing Script (cont.)
![Page 8: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/8.jpg)
Script Processing Script (cont.)
![Page 9: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/9.jpg)
Script
Worker
Worker
Worker
![Page 10: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/10.jpg)
Setting up Gearman serverlatest version: 0.24
![Page 11: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/11.jpg)
aptitude install gearman-job-server
![Page 12: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/12.jpg)
Setting up PECL Extension
![Page 13: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/13.jpg)
pecl install channel://pecl.php.net/gearman-0.8.0.tgz
![Page 14: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/14.jpg)
extension=gearman.so
![Page 15: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/15.jpg)
user@server:~# gearmand
![Page 16: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/16.jpg)
Basic Usage
![Page 17: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/17.jpg)
Worker
![Page 18: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/18.jpg)
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));
while($worker->work()) {}
![Page 19: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/19.jpg)
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));
while($worker->work()) {}
![Page 20: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/20.jpg)
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));
while($worker->work()) {}
![Page 21: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/21.jpg)
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));
while($worker->work()) {}
![Page 22: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/22.jpg)
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));
while($worker->work()) {}
![Page 23: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/23.jpg)
namespace Cxo;
class Image{ public function resize(\GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
![Page 24: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/24.jpg)
namespace Cxo;
class Image{ public function resize(\GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
![Page 25: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/25.jpg)
namespace Cxo;
class Image{ public function resize(\GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
![Page 26: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/26.jpg)
namespace Cxo;
class Image{ public function resize(\GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
![Page 27: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/27.jpg)
Synchronous Jobs
![Page 28: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/28.jpg)
$client = new GearmanClient();$client->addServer();
$client->do('imageResize', '/tmp/someimage.jpg');
![Page 29: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/29.jpg)
$client = new GearmanClient();$client->addServer();
$client->do('imageResize', '/tmp/someimage.jpg');
![Page 30: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/30.jpg)
$client = new GearmanClient();$client->addServer();
$client->do('imageResize', '/tmp/someimage.jpg');
![Page 31: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/31.jpg)
$client = new GearmanClient();$client->addServer();
$client->do('imageResize', '/tmp/someimage.jpg');
![Page 32: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/32.jpg)
$client->doHigh();
![Page 33: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/33.jpg)
$client->do() returns worker result
![Page 34: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/34.jpg)
Asynchronous Jobs
![Page 35: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/35.jpg)
$client->doBackground( 'imageResize', '/tmp/someimage.jpg');
![Page 36: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/36.jpg)
$client->doBackground() returns job handle
![Page 37: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/37.jpg)
Tasks
![Page 38: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/38.jpg)
$client->addTask( 'imageResize', '/tmp/someimage.jpg');
![Page 39: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/39.jpg)
$client->addTaskBackground( 'imageResize', '/tmp/someimage.jpg');
![Page 40: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/40.jpg)
$client->runTasks();
![Page 41: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/41.jpg)
Scale by adding more workers(as long as you‘re not running jobs synchronously)
![Page 42: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/42.jpg)
![Page 43: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/43.jpg)
Script (cont.)ProcessingScript
![Page 44: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/44.jpg)
Script (cont.)Processing
Processing
Processing
Script
![Page 45: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/45.jpg)
Job status
![Page 46: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/46.jpg)
$handle = $client->doBackground();
![Page 47: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/47.jpg)
$status = $client->jobStatus($handle);
![Page 48: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/48.jpg)
array(4) { [0]=> bool(true) // Is the job known? [1]=> bool(true) // Is the job running? [2]=> int(4) // Numerator [3]=> int(10) // Denominator}
![Page 49: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/49.jpg)
$job->sendStatus(4, 10);
![Page 50: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/50.jpg)
Error handling
![Page 51: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/51.jpg)
GEARMAN_SUCCESS
![Page 52: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/52.jpg)
GEARMAN_WORK_FAIL
![Page 53: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/53.jpg)
$worker->returnCode();
![Page 54: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/54.jpg)
$client->returnCode();
![Page 55: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/55.jpg)
$job->sendFail();
![Page 56: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/56.jpg)
$job->sendWarning(‘Something went wrong‘);
![Page 57: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/57.jpg)
$job->sendException(‘Something went wrong‘);
![Page 58: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/58.jpg)
$message = $client->do();
![Page 59: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/59.jpg)
Managing workers
![Page 60: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/60.jpg)
supervisord
![Page 61: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/61.jpg)
Memory consumption
![Page 62: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/62.jpg)
Persistence
![Page 63: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/63.jpg)
“Whuh?“
![Page 64: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/64.jpg)
$client->doJobHandle();doesn‘t do what it should - and many more functions as well
![Page 65: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/65.jpg)
GearmanClient::setOptions
Return Values: Always returns TRUE
![Page 66: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/66.jpg)
do is a keyword
![Page 67: Distributed Work with Gearman · Dominik Jungowski 27 years old Scrum Coach at inovex GmbH Psychology student at Fernuni Hagen](https://reader034.vdocuments.site/reader034/viewer/2022052006/601a6910e0b2fd2e687326fe/html5/thumbnails/67.jpg)
Thank you!
joind.in: http://joind.in/3907Twitter: @djungowski
Blog: www.agileblog.org