Transcript
Page 1: Khanh-Nguyen - Gearman - distributed process solution

GearmanDistributed Process Solution

Created by Google Drive Presentation.

Page 2: Khanh-Nguyen - Gearman - distributed process solution

Introduction$ whoami

########################################################

#### Name : Nguyen Duy Khanh ####

#### Job : Student of HCMUS, Part-timer at PNC ####

#### My skills : PHP, MySQL, JS ####

#### Love : New technology ####

########################################################

$|

Page 3: Khanh-Nguyen - Gearman - distributed process solution

Problems

HEAVY WORKLOADfunction main() {

...doSomeThing();doSomeThingBig();doSomeThingBigBig();doSomeThingVeryBig();…return result;

}

Page 4: Khanh-Nguyen - Gearman - distributed process solution

Problems

console.log(result);

Page 5: Khanh-Nguyen - Gearman - distributed process solution
Page 6: Khanh-Nguyen - Gearman - distributed process solution

Solution

Worker 2

Worker 1

Worker...

Worker n

Give me a job, my workers will do it for you.

Page 7: Khanh-Nguyen - Gearman - distributed process solution

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

Page 8: Khanh-Nguyen - Gearman - distributed process solution

Installation1. Download source code [ https://launchpad.net/gearmand ].2. Compile and install from tarball.

3. Starting gearman.

tar xzf gearmand-X.Y.tar.gz

cd gearmand-X.Y

./configure

make

make install

gearman -d

Page 9: Khanh-Nguyen - Gearman - distributed process solution

Gearman Architecture

Customer

Job Manager

Worker

Page 10: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python

Worker Node.JS

Worker PHP

Hey, I can send email. Let me do it !!!

Page 11: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS

Worker PHP

Page 12: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python

Worker Node.JS

Worker PHP

And I can push notification. Let me try !!!

Page 13: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP

Page 14: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python

Worker Node.JS

Worker PHP

Haha, I can do them all !!!

Page 15: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

Page 16: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

I need send an email to [email protected] , please help me !

Page 17: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

OK, Let me see. Aaah … We have 2 workers can do it for you. But, Worker Python is busy, let Worker PHP do it.

Page 18: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

Hey Worker PHP, please send an email to [email protected]

Page 19: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

OK Boss, email has sent to [email protected]

Page 20: Khanh-Nguyen - Gearman - distributed process solution

How does it work ?

Client

Job Manager

Worker Python(send_email)

Worker Node.JS(push_notify)

Worker PHP(send_email, push_notify)

Hi client, your email has sent to [email protected].

Page 21: Khanh-Nguyen - Gearman - distributed process solution

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

Page 22: Khanh-Nguyen - Gearman - distributed process solution

Hello world !!!worker1.js

Page 23: Khanh-Nguyen - Gearman - distributed process solution

Hello world !!!worker2.py

Page 24: Khanh-Nguyen - Gearman - distributed process solution

Hello world !!!client.php

Page 25: Khanh-Nguyen - Gearman - distributed process solution

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 ]

Page 26: Khanh-Nguyen - Gearman - distributed process solution

Use-cases❏ Scatter/Gather

❏ Map - Reduce

❏ Asynchronous Queues

❏ Pipeline Processing

Page 27: Khanh-Nguyen - Gearman - distributed process solution

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.

Page 28: Khanh-Nguyen - Gearman - distributed process solution

Scatter / Gather

Client

Db Query

Resize Image

Search

Page 29: Khanh-Nguyen - Gearman - distributed process solution

Map / Reduce

Page 30: Khanh-Nguyen - Gearman - distributed process solution

Asynchronous Queues

● Most popular use-case.

● Do something needn’t immediate processing.

○ Ex : send emails, push notification, index data,

crawling, ...

● Allows for batch operations.

Page 31: Khanh-Nguyen - Gearman - distributed process solution

Asynchronous Queuesfunction tweet(msg) {

// Insert to databasedb.insert(msg);// Background tasksgearman.push_notify();// Returnreturn true;

}

Page 32: Khanh-Nguyen - Gearman - distributed process solution

Pipeline Processing

● Do related thing.

○ Ex : search engine, data analytic, ...

● Chain workers to send data to next step.

Page 33: Khanh-Nguyen - Gearman - distributed process solution

Pipeline Processing

WorkerStep 1 Client Worker

Step 2 Client WorkerLast Step

Main Client Output

Page 34: Khanh-Nguyen - Gearman - distributed process solution

Examples

MongoDB Workers“parse_rss”

RSS Sources

ReloadRequest

Gearman Client End

Workers“crawling”

Have new items ?

No

Crawl new items

GEARMAN Auto News Crawling System

● Manager : GEARMAN

● Workers : Python

● Webserver : Node.JS

● Web Framework : Express

● Database : MongoDB

● Client Script : jQuery

Page 35: Khanh-Nguyen - Gearman - distributed process solution

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.

Page 36: Khanh-Nguyen - Gearman - distributed process solution

Gearman Admin GUI● Command Line Tool : http://gearman.info/bin/gearadmin.html

● Gearman-Monitor [ PHP ] : https://github.com/yugene/Gearman-Monitor

● GearmanUI [ PHP ] : http://rripado.info/gearmanui/

Page 37: Khanh-Nguyen - Gearman - distributed process solution
Page 38: Khanh-Nguyen - Gearman - distributed process solution

THE N THANK YOU !!! D

Page 39: Khanh-Nguyen - Gearman - distributed process solution

About UsAuthor : Khanh Nguyen DuyFind me at : [email protected]

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


Top Related