Distributed work with Gearman
Upcoming SlideShare
Loading in...5
×
 

Distributed work with Gearman

on

  • 3,220 views

 

Statistics

Views

Total Views
3,220
Views on SlideShare
1,794
Embed Views
1,426

Actions

Likes
3
Downloads
32
Comments
0

7 Embeds 1,426

http://www.phpdevblog.net 716
http://phpdevblog.niknovo.com 638
http://phpdevblog.net 66
http://translate.googleusercontent.com 3
http://www.phpdevblog.niknovo.com 1
http://www.php-talks.com 1
http://www.365dailyjournal.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Distributed work with Gearman Distributed work with Gearman Presentation Transcript

  • Dominik Jungowski / CHIP Xonio Online GmbHDistributed work withGearman
  • Law of two feet
  • Dominik Jungowski27 years oldScrumMaster at CHIP OnlinePsychology student at Fernuni Hagen
  • TopicsWhat is Gearman?Setting up GearmanBasic UsageJob statusError handlingManaging workers
  • What is Gearman?
  • Script Processing Script (cont.)
  • Script Processing Script (cont.)
  • WorkerScript 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.)
  • ProcessingScript 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::setOptionsReturn Values: Always returns TRUE
  • do is a keyword
  • Thank you!joind.in: http://joind.in/3907 Twitter: @djungowski Blog: www.phpdevblog.net