Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. In other words, it is the nervous system for how distributed processing communicates.
6. Solution
Give me a job, my
workers will do it
for you.
Worker 1
Worker 2
Worker...
Worker n
7. Gearman
❏ GEARMAN → MANAGER
❏ Open Source.
❏ Multi-language API.
❏ Multi-threaded ( 50k jobs / second ).
❏ Ultra fast ( written in C/C++ ).
❏ No limits on message size.
❏ Failover
8. Installation
1.
2.
Download source code [ https://launchpad.net/gearmand ].
Compile and install from tarball.
tar xzf gearmand-X.Y.tar.gz
cd gearmand-X.Y
./configure
make
make install
3.
Starting gearman.
gearman -d
10. How does it work ?
Client
Hey, I can send email.
Let me do it !!!
Worker Python
Worker Node.JS
Job Manager
Worker PHP
11. How does it work ?
Client
Worker Python
(send_email)
Worker Node.JS
Job Manager
Worker PHP
12. How does it work ?
Client
And I can push
notification. Let me try !!!
Worker Python
Worker Node.JS
Job Manager
Worker PHP
13. How does it work ?
Client
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
14. How does it work ?
Client
Haha, I can do them all !!!
Worker Python
Worker Node.JS
Job Manager
Worker PHP
15. How does it work ?
Client
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
16. How does it work ?
Client
I need send an email to
abc@xyz.com , please
help me !
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
17. How does it work ?
Client
OK, Let me see. Aaah …
We have 2 workers can do
it for you. But, Worker
Python is busy, let Worker
PHP do it.
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
18. How does it work ?
Client
Hey Worker PHP, please
send an email to
abc@xyz.com
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
19. How does it work ?
Client
OK Boss, email has sent
to abc@xyz.com
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
20. How does it work ?
Client
Hi client, your email has
sent to abc@xyz.com.
Worker Python
(send_email)
Worker Node.JS
(push_notify)
Job Manager
Worker PHP
(send_email, push_notify)
21. Hello world !!!
Install Node.js API
$ npm install node-gearman
Install PHP API
$ pecl install gearman
Install Python API
$ pip install gearman
or
$ easy_install gearman
25. Hello world !!!
●
Python and C/C++ and a good choices for workers.
●
PHP, Node.js should be client than worker. [ PHP Worker often crash after
1-2 hours because memory leak ]
27. Scatter / Gather
● Perform a number of task concurrently.
○ Ex : Db Query, Image Processing, Location Search,
Full-text Search…
● Take advantage of many tier.
● Speed up your web applications.
● Tasks don’t need to be related.
30. Asynchronous Queues
● Most popular use-case.
● Do something needn’t immediate processing.
○ Ex : send emails, push notification, index data,
crawling, ...
● Allows for batch operations.
34. Examples
GEARMAN Auto News Crawling System
Reload
Request
MongoDB
●
Manager : GEARMAN
●
Workers
“parse_rss”
Gearman Client
Webserver : Node.JS
No
Workers : Python
●
RSS
Sources
●
Web Framework : Express
●
Database : MongoDB
●
Client Script : jQuery
Have new items ?
Crawl new items
Workers
“crawling”
End
35. Persistent Queues
❏
By default, jobs are only stored in memory.
❏
Various contributions from community :
❏
MySQL / Drizzle
❏
PostgreSQL
❏
SQLite
❏
Tokyo Cabinet
❏
memcached
❏
Hope MongoDB (or an NOSQL DB) coming soon.
39. About Us
Author : Khanh Nguyen Duy
Find me at : admin@ndksolution.com
Presentation made for “Javascript HoChiMinh City Meetup”
You can find us at :
● http://meetup.com/JavaScript-Ho-Chi-Minh-City/
● https://www.facebook.com/JavaScriptHCMC
● https://plus.google.com/u/0/communities/116105314977285194967