verteilte und asynchrone berechnung mit gearman und asynchr… · •swig (python, ruby, ...)...
TRANSCRIPT
![Page 1: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/1.jpg)
Verteilte und asynchrone Berechnung mit Gearman
Dennis SchönPrincipal Software Architect
Berlin, 12/11/09
![Page 2: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/2.jpg)
Why?
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 2
![Page 3: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/3.jpg)
Kittens!(LiveJournal.com Image Processing)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 3
![Page 4: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/4.jpg)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Apache
PHP Resize
Apache
PHP Resize
Apache
PHP Resize
Apache
PHP Resize...
Kittens!(LiveJournal.com Image Processing)
4
![Page 5: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/5.jpg)
History
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•Danga - Brad Fitzpatrick & company
-Related to memcached, MogileFS, ...
•Anagram for “manager”
-Gearman, like managers, assign the tasks but do none of the real work themselves
•Digg: 45+ Server, 400K jobs/day
•Yahoo: 60+ Server, 6M jobs/day
•XING: 45+ Server, 15M jobs/day
•LiveJournal, SixApart, DealNews, ...
5
![Page 6: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/6.jpg)
Recent Development
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•Rewrite in C
•New language APIs
-PHP/C, Perl/C Drizzle, MySQL, Java, Python/C, JMS, Erlang, OCaml,...
•Command line tool
•Protocol additions
•Multi-threaded (50k jobs/second)
•Persistent queues
•Pluggable protocol
6
![Page 7: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/7.jpg)
Features
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•Open Source (mostly BSD)
•Multi-language
-Mix clients and workers from different APIs
•Flexible Application Design
-Not restricted to a single distributed model
•Simple & Fast
•Embeddable
•Small & lightweight for applications of all sizes
•No Single Point of Failure
7
![Page 8: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/8.jpg)
Basics
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•Gearman provides a distributed application framework
•Uses TCP port 4730 (was port 7003)
•Client - Create jobs to be run and send them to a job server
•Worker - Register with a job server and grab jobs to run
•Job Server - Coordinate the assignment from clients to workers, handle restarts
8
![Page 9: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/9.jpg)
Gearman Stack
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Client Application
Gearman Job Server
Gearman Worker API(C, Perl, PHP, ...)
Worker Application
Gearman Client API(C, Perl, PHP, MySQL UDF, ...)
Provided by Gearman
Your Application
9
![Page 10: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/10.jpg)
No Single Point of Failure
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Job Server
Client Client Client Client
Worker Worker Worker Worker
Job Server
10
![Page 11: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/11.jpg)
Hello World
$client= new Gearman::XS::Client;$client->add_server();print $client->do('reverse', 'Hello World!');
$worker= new Gearman::XS::Worker;$worker->add_server();$worker->add_function("reverse", 0, \&reverse, 0);
while (1) { $worker->work();}
sub reverse { my ($job) = @_; return reverse($job->workload());}
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 11
![Page 12: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/12.jpg)
Hello World
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$ gearmand -d
$ perl worker.pl &[1] 7929
$ perl client.pl!dlroW olleH
12
![Page 13: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/13.jpg)
How Is This Useful?
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•Natural load balancing
-Workers are notified and ask for work, not forced
•Multi-language integration
•Distributed parallel processing
•Possibly closer to the data
•Synchronous and Asynchronous queues
13
![Page 14: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/14.jpg)
Back to the Kittens
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 14
![Page 15: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/15.jpg)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Apache
PHP Resize
Apache
PHP Resize
Apache
PHP Resize
Apache
PHP Resize...
Kittens!(LiveJournal.com Image Processing)
15
![Page 16: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/16.jpg)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Kittens!(LiveJournal.com Image Processing)
Apache
PHP
Gearman Job Server
Apache
PHP
Apache
PHP
Gearman Job Server
StorageNFS, mogileFS
ResizeWorker
ResizeWorker
ResizeWorker
ResizeWorker
16
![Page 17: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/17.jpg)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Image Resize Worker
$worker= new Gearman::XS::Worker;$worker->add_server();$worker->add_function("resize", 0, \&resize, 0);
while (1) { $worker->work();}
sub resize { my ($job) = @_; my $image = Image::Magick->new(); $image->BlobToImage( $job->workload() ); $image->Scale(width => 200, height => 150); return $image->ImageToBlob();}
17
![Page 18: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/18.jpg)
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Image Resize Worker
$ gearmand -d
$ perl resize.pl &[1] 17529
$ gearman -f resize < large.jpg > thumb.jpg
$ ls -sh large.jpg thumb.jpg3.0M large.jpg 32K thumb.jpg
18
![Page 19: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/19.jpg)
Gearman @ XING
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 19
![Page 20: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/20.jpg)
•8 million members
•15 million dynamic page impressions per day
•300+ servers
•2 data centers
•3 main development languages
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 20
![Page 21: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/21.jpg)
•2 job servers
•20 dedicated worker servers
•300 Gearman jobs / second avg.
•700+ Gearman jobs / second peak
Setup
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 21
![Page 22: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/22.jpg)
Munin Statistics
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 22
![Page 23: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/23.jpg)
Admin Interface
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 23
![Page 24: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/24.jpg)
Monitoring
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 24
![Page 25: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/25.jpg)
•Scale
•Upload
•Synchronous
-return success/failure
•ImageMagick
•Security record
Image Upload
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Apache
Perl
Job Server
Apache
Perl
Apache
Perl
Image Server
Resize / UploadWorker (Perl)
Image ServerImage Server
Apache
Perl
Job Server
Resize / UploadWorker (Perl)
Resize / UploadWorker
Resize / UploadWorker
Resize / UploadWorker (Perl)
25
![Page 26: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/26.jpg)
•Import contacts from webmail
•Proprietary software (PHP)
•Synchronous
-return list of contacts
Addressbook Import
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Apache
Perl
Job Server
Apache
Perl
Apache
Perl
Addressbok Import (PHP)
Apache
Perl
Job Server
Addressbok Import (PHP)
Resize / UploadWorker
Resize / UploadWorker
Addressbok Import (PHP)
26
![Page 27: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/27.jpg)
•Flag E-Mail addresses
•Command line client
•Synchronous
•return success/failure
Mark E-Mail addresses bounced
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Command Line Client
Job Server
Mark E-Mail(Perl)
Job Server
Mark E-Mail(Perl)
Resize / UploadWorker
Resize / UploadWorker
Mark E-Mail(Perl)
Mail Server
Command Line Client
Mail Server
Command Line Client
Mail Server
27
![Page 28: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/28.jpg)
•check all form parameters
•CGI::IDS
•Asynchronous
- log malicious requests
•+700 jobs/second peak
IDS
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Apache
Perl
Job Server
Apache
Perl
Apache
Perl
IDS Check (Perl)
Apache
Perl
Job Server
IDS Check (Perl) Resize / UploadWorker
Resize / UploadWorkerIDS Check (Perl)
28
![Page 29: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/29.jpg)
Weekly Statistics Newsletter
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 29
![Page 30: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/30.jpg)
•~1 million newsletter per night
•3 step process
-cronjob creates one NL job per user
‣sends 2000 user batched to job server
-NL job triggers one render job per box
‣concurrent interface waits until all boxes are rendered
-NL job assembles newsletter and triggers send job
Weekly Statistics Newsletter
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 30
![Page 31: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/31.jpg)
Weekly Statistics Newsletter
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Cron Server
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
31
![Page 32: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/32.jpg)
Weekly Statistics Newsletter
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Cron Server
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
Render NLStatistics Box
Birthday Box
Jobs Box
...
Send NL
32
![Page 33: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/33.jpg)
Weekly Statistics Newsletter
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
Render NL
Cron Server
Render NLRender NLRender NLBirthday Box
(Perl)
Render Statistics Box
Render Statistics BoxStatistics Box
(Perl)
Jobs Box(Ruby)
Birthday Box (Perl)
Birthday Box (Perl)
Jobs Box(Ruby)Jobs Box(Ruby)
Send NL
Job ServerJob Server
Send NLSend NLSend NL
33
![Page 34: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/34.jpg)
APIs
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 34
![Page 35: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/35.jpg)
APIs
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•C (libgearman)
-PHP, Perl::XS, Drizzle, MySQL, PostgreSQL
•SWIG (Python, Ruby, ...)
•Perl
•PHP
•Java
•Python
•Ruby
•Erlang
•...
35
![Page 36: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/36.jpg)
Command Line Tool
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
•gearman
-Included in C server and library package
-Command line and shell script interface
•Client mode
- ls | gearman -f function
-gearman -f function < file
-gearman -f function “some data”
•Worker mode
-gearman -w -f function -- wc -l
-gearman -w -f function ./script.sh
36
![Page 37: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/37.jpg)
Command Line Tool
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$ gearmand -d
$ gearman -w -f test --grep lib &[1] 7622
$ ls / | gearman -f testliblib32lib64
37
![Page 38: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/38.jpg)
Client API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 38
![Page 39: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/39.jpg)
•Create client object
-Can have multiple objects in an application
-Server lists, options, ...
Client API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$client= new Gearman::XS::Client;$client->add_server();
$client= new Gearman::XS::Client;$client->add_servers("10.0.0.1, 10.0.0.2:7003");
$client= new Gearman::XS::Client;$client->add_server("10.0.0.1");$client->add_server("10.0.0.2", 7003);
39
![Page 40: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/40.jpg)
•One job at a time
-*do* functions and methods
$client= new Gearman::XS::Client;$client->add_server();
print $client->do("reverse", "Hello World!");
print $client->do_high("reverse", "Hello World!");
print $client->do_low("reverse", "Hello World!");
Client API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 40
![Page 41: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/41.jpg)
•Multiple jobs at a time
-*task* functions and methods
Client API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$client= new Gearman::XS::Client;$client->add_server();
$client->add_task("reverse", "Hello World!");$client->add_task_high("reverse", "Hello High!");$client->add_task_low("reverse", "Hello Low!");
$client->set_complete_fn(\&completed_cb);$client->run_tasks(); # blocks
sub completed_cb { my ($task) = @_; print $task->data();}
41
![Page 42: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/42.jpg)
•A job is a task
•A task is not always a job
•Check status of background job
-Not a job, but is a task
-Send job handle, receive status
-$client->job_status()
-$client->add_task_status()
•Clients deal tasks
•Workers deal with jobs
Tasks vs Jobs
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 42
![Page 43: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/43.jpg)
•Foreground (Synchronous)
-$client->do()
•Background (Asynchronous)
-$client->do_background()
•High and Low priority
-$client->do_high()
-$client->do_low()
•Mix and match
-$client->do_high_background()
Job Attributes
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 43
![Page 44: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/44.jpg)
•Application data/state for tasks
•Optional Unique Key
-UUID generated if none gived
-Coalesce jobs in job server
-Only one worker per key at any time
-All clients get the same response
-Resizing an image
‣Multiple clients submit jobs at the same time
‣Workers runs once, all clients get thumbnail
Job Attributes
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 44
![Page 45: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/45.jpg)
•Queue jobs to run
•Register callbacks for interesting events
•Run tasks
-$client->run_tasks()
-Returns when all tasks are complete
•No guarantee on response order
Concurrent Task API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 45
![Page 46: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/46.jpg)
•Available Callbacks
-set_workload_fn() - Streaming job workload
-set_created_fn() - Job created in server
-set_data_fn() - Partial data response
-set_warning_fn() - Partial warning response
-set_status_fn() - Status (X/Y done)
-set_complete_fn() - Job complete
-set_exception_fn() - Exception caught (deprecated Perl)
-set_fail_fn() - Job failed
-clear_fn() - Clear all set callbacks
Concurrent Task API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 46
![Page 47: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/47.jpg)
Worker API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 47
![Page 48: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/48.jpg)
•Create worker object
-Can have multiple objects in an application
-Server lists, options, ...
Worker API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$worker= new Gearman::XS::Worker;$worker->add_server();
$worker= new Gearman::XS::Worker;$worker->add_servers("10.0.0.1, 10.0.0.2:7003");
$worker= new Gearman::XS::Worker;$worker->add_server("10.0.0.1");$worker->add_server("10.0.0.2", 7003);
48
![Page 49: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/49.jpg)
•Register function abilities
-Function name
-Local callback function
•Wait for jobs on those functions
•Will only run one job at a time
Worker API
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$worker= new Gearman::XS::Worker;$worker->add_server();
$worker->add_function("function1", \&first_callback);$worker->add_function("function2", \&common_callback);$worker->add_function("function3", \&common_callback);
while (1) { $worker->work();}
49
![Page 50: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/50.jpg)
•Have access to $job object
•Get job information
-$job->workload() - Get job workload
-$job->function_name() - Get function name
-$job->unique() - Get unique key
-$job->handle() - Get job handle
Worker Callback Function
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 50
![Page 51: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/51.jpg)
•Send intermediate job responses
-$job->send_data(...) - Send partial result
-$job->send_warning(...) - Send warning
-$job->send_status(X, Y) - Send X/Y status
•Return value sent back to caller
•Don’t bother if it’s a background job
•Except $job->status(X, Y)
Worker Callback Function
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 51
![Page 52: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/52.jpg)
•Can also return failure
Worker Callback Function
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$worker= new Gearman::XS::Worker;$worker->add_server();$worker->add_function("reverse", 0, \&always_fail, 0);
sub always_fail { my ($job) = @_; return GEARMAN_WORK_FAIL;}
52
![Page 53: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/53.jpg)
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 53
![Page 54: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/54.jpg)
•Listens on port 4730
•Clients and workers connect
•Handle job assignment
•Restart jobs on worker failure
•Advanced features
-Pluggable persistent queue
-Pluggable protocols
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 54
![Page 55: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/55.jpg)
•gearmand --help
•Common options
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
-d, --daemon-h, --help-l, --log-file=FILE-p, --port=PORT-P, --pid-file=FILE-t, --threads=THREADS-u, --user=USER-v, --verbose
55
![Page 56: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/56.jpg)
•Administrative Protocol
-Telnet port 4730
•workers
-Lists connected clients
•status
-Lists registered functions
•maxqueue
-Sets the maximum queue size for a function
•shutdown
-Shutdown the server
-Optional “graceful” argument
•version
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 56
![Page 57: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/57.jpg)
•Administrative Protocol
- “workers” command
-IP address
-Client ID
-List of functions
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$ telnet obc-grm42-1 4730Escape character is '^]'.workers949 10.43.12.6 - : resize_image948 10.43.12.7 - : ids_check940 10.43.12.5 - : mark_email ids_check...
57
![Page 58: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/58.jpg)
•Administrative Protocol
- “status” command
-Function
-Total
-Running
-Available
Job Server
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$ telnet obc-grm42-1 4730Escape character is '^]'.statusresize_image!0! 0! 10ids_check!0! 0! 10mark_email!0! 0! 10...
58
![Page 59: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/59.jpg)
•Only for background jobs
•Specify -q <queue> option
•libdrizzle module for Drizzle and MySQL
•libmemcached
•PostgreSQL
•sqlite3
•Flat file
Persistent Queues
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 59
![Page 60: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/60.jpg)
•Handle packet parsing and packing
•Optionally handle raw socket I/O
•HTTP protocol
•Others coming soon
-memcached
-XMPP
Pluggable Protocol
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 60
![Page 61: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/61.jpg)
•GET and POST requests
-Send workload with POST, Content-Length
•Function name from URL
•Optional headers
-X-Gearman-Unique: <unique key>
-X-Gearman-Background: true
-X-Gearman-Priority: <high/low>
•Other headers ignored for now
HTTP Protocol
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 61
![Page 62: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/62.jpg)
HTTP Protocol
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09
$ gearmand -r http -d
<start reverse worker>
$ nc localhost 8080POST /reverse HTTP/1.1Content-Length: 12
Hello World!
HTTP/1.0 200 OKX-Gearman-Job-Handle: H:lap:1Content-Length: 12Server: Gearman/0.9
!dlroW olleH
62
![Page 63: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/63.jpg)
•http://gearman.org
•#gearman on irc.freenode.net
•http://groups.google.com/group/gearman
•http://xing.com/career/ :-)
Get involved
Verteilte und asynchrone Berechnung mit Gearman | Dennis Schön | Berlin, 12/11/09 63
![Page 64: Verteilte und asynchrone Berechnung mit Gearman und asynchr… · •SWIG (Python, Ruby, ...) •Perl •PHP •Java •Python •Ruby •Erlang •... 35. Command Line Tool Verteilte](https://reader033.vdocuments.net/reader033/viewer/2022052719/5f074bd57e708231d41c4855/html5/thumbnails/64.jpg)
Presentation Titel | Author | City, 11/30/09 17
Thank youfor your kind attention!