Your SlideShare is downloading. ×
0
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Distributed work with Gearman
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Distributed work with Gearman

3,295

Published on

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

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×