0
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‘));w...
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction(     ‘imageResize‘,     array($image, ‘resize‘));w...
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction(     ‘imageResize‘,     array($image, ‘resize‘));w...
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction(     ‘imageResize‘,     array($image, ‘resize‘));w...
$worker = new GearmanWorker();$worker->addServer();$worker->addFunction(     ‘imageResize‘,     array($image, ‘resize‘));w...
namespace Cxo;class Image{     public function resize(GearmanJob $job)     {          $tmpFile = $job->workload();        ...
namespace Cxo;class Image{     public function resize(GearmanJob $job)     {          $tmpFile = $job->workload();        ...
namespace Cxo;class Image{     public function resize(GearmanJob $job)     {          $tmpFile = $job->workload();        ...
namespace Cxo;class Image{     public function resize(GearmanJob $job)     {          $tmpFile = $job->workload();        ...
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)       // Nume...
$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
Distributed work with Gearman
Distributed work with Gearman
Upcoming SlideShare
Loading in...5
×

Distributed work with Gearman

3,314

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,314
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
35
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Distributed work with Gearman"

  1. 1. Dominik Jungowski / CHIP Xonio Online GmbHDistributed work withGearman
  2. 2. Law of two feet
  3. 3. Dominik Jungowski27 years oldScrumMaster at CHIP OnlinePsychology student at Fernuni Hagen
  4. 4. TopicsWhat is Gearman?Setting up GearmanBasic UsageJob statusError handlingManaging workers
  5. 5. What is Gearman?
  6. 6. Script Processing Script (cont.)
  7. 7. Script Processing Script (cont.)
  8. 8. WorkerScript Worker Worker
  9. 9. Setting up Gearman server latest version: 0.24
  10. 10. aptitude install gearman-job-server
  11. 11. Setting up PECL Extension
  12. 12. pecl install channel://pecl.php.net/gearman-0.8.0.tgz
  13. 13. extension=gearman.so
  14. 14. user@server:~# gearmand
  15. 15. Basic Usage
  16. 16. Worker
  17. 17. $worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));while($worker->work()) {}
  18. 18. $worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));while($worker->work()) {}
  19. 19. $worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));while($worker->work()) {}
  20. 20. $worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));while($worker->work()) {}
  21. 21. $worker = new GearmanWorker();$worker->addServer();$worker->addFunction( ‘imageResize‘, array($image, ‘resize‘));while($worker->work()) {}
  22. 22. namespace Cxo;class Image{ public function resize(GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
  23. 23. namespace Cxo;class Image{ public function resize(GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
  24. 24. namespace Cxo;class Image{ public function resize(GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
  25. 25. namespace Cxo;class Image{ public function resize(GearmanJob $job) { $tmpFile = $job->workload(); // Resizing takes place here ... return $finalFileName; }}
  26. 26. Synchronous Jobs
  27. 27. $client = new GearmanClient();$client->addServer();$client->do(imageResize, /tmp/someimage.jpg);
  28. 28. $client = new GearmanClient();$client->addServer();$client->do(imageResize, /tmp/someimage.jpg);
  29. 29. $client = new GearmanClient();$client->addServer();$client->do(imageResize, /tmp/someimage.jpg);
  30. 30. $client = new GearmanClient();$client->addServer();$client->do(imageResize, /tmp/someimage.jpg);
  31. 31. $client->doHigh();
  32. 32. $client->do() returns worker result
  33. 33. Asynchronous Jobs
  34. 34. $client->doBackground( imageResize, /tmp/someimage.jpg);
  35. 35. $client->doBackground() returns job handle
  36. 36. Tasks
  37. 37. $client->addTask( imageResize, /tmp/someimage.jpg);
  38. 38. $client->addTaskBackground( imageResize, /tmp/someimage.jpg);
  39. 39. $client->runTasks();
  40. 40. Scale by adding more workers (as long as you‘re not running jobs synchronously)
  41. 41. Script Processing Script (cont.)
  42. 42. ProcessingScript Processing Script (cont.) Processing
  43. 43. Job status
  44. 44. $handle = $client->doBackground();
  45. 45. $status = $client->jobStatus($handle);
  46. 46. array(4) { [0]=> bool(true) // Is the job known? [1]=> bool(true) // Is the job running? [2]=> int(4) // Numerator [3]=> int(10) // Denominator}
  47. 47. $job->sendStatus(4, 10);
  48. 48. Error handling
  49. 49. GEARMAN_SUCCESS
  50. 50. GEARMAN_WORK_FAIL
  51. 51. $worker->returnCode();
  52. 52. $client->returnCode();
  53. 53. $job->sendFail();
  54. 54. $job->sendWarning(‘Something went wrong‘);
  55. 55. $job->sendException(‘Something went wrong‘);
  56. 56. $message = $client->do();
  57. 57. Managing workers
  58. 58. supervisord
  59. 59. Memory consumption
  60. 60. Persistence
  61. 61. “Whuh?“
  62. 62. $client->doJobHandle();doesn‘t do what it should - and many more functions as well
  63. 63. GearmanClient::setOptionsReturn Values: Always returns TRUE
  64. 64. do is a keyword
  65. 65. Thank you!joind.in: http://joind.in/3907 Twitter: @djungowski Blog: www.phpdevblog.net
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×