48
Introduction to ZeroMQ Howard Lee 2013/05/16 1 13年5月17星期五

Introduction to ZeroMQ

Embed Size (px)

DESCRIPTION

For 2013 micro sessions of CNA@CCU.

Citation preview

Page 1: Introduction to ZeroMQ

Introduction to ZeroMQ

Howard Lee2013/05/16

113年5月17⽇日星期五

Page 2: Introduction to ZeroMQ

AnnounceØMQ, ZeroMQ, and 0MQ used in this slides are trademarks of iMatix Corporation

ØMQ is copyright (c) Copyright (c) 2007-2012 iMatix Corporation and Contributors. ØMQ is free software licensed under the LGPL.

Above statements are referred from footer of its website

213年5月17⽇日星期五

Page 3: Introduction to ZeroMQ

Outline

Concept

Demo

Reference

313年5月17⽇日星期五

Page 4: Introduction to ZeroMQ

If you have known these, you will know what I say

Java, Ruby

Network programming

Multithread

Background knowledge

413年5月17⽇日星期五

Page 5: Introduction to ZeroMQ

Online chat room is a basic program for beginner of network programming

513年5月17⽇日星期五

Page 6: Introduction to ZeroMQ

How do you do when building a program of online chat-room for multi-players?

613年5月17⽇日星期五

Page 7: Introduction to ZeroMQ

Centralize-type Server

Client

ClientClient

713年5月17⽇日星期五

Page 8: Introduction to ZeroMQ

Good

What if the server broken......?

813年5月17⽇日星期五

Page 9: Introduction to ZeroMQ

-- Howard Lee said :p2013.05.16

Everything is important means nothing is important

913年5月17⽇日星期五

Page 10: Introduction to ZeroMQ

Everyone is a server means no one is a server

1013年5月17⽇日星期五

Page 11: Introduction to ZeroMQ

Client

ClientClient De-centralize

1113年5月17⽇日星期五

Page 12: Introduction to ZeroMQ

Previous page about de-centralize use many sockets

More sockets grow exponential when a client joins!

1213年5月17⽇日星期五

Page 13: Introduction to ZeroMQ

Here is

1313年5月17⽇日星期五

Page 14: Introduction to ZeroMQ

Apply scenarios above pages

It can do more!

We only pick up above two scenarios at today’s lightning session

1413年5月17⽇日星期五

Page 15: Introduction to ZeroMQ

Actor model

De-centralize --> zero broker

Distributed computing

Concept

1513年5月17⽇日星期五

Page 16: Introduction to ZeroMQ

Actor model in ZeroMQ

REQuest-REPly

PUBlish-SUBcribe

Pipeline

1613年5月17⽇日星期五

Page 17: Introduction to ZeroMQ

Actor model in ZeroMQ

One machine can play many actors simultaneously

Better scalability than data-centric distributed computing because easier to extend

1713年5月17⽇日星期五

Page 18: Introduction to ZeroMQ

REQuest-REPly

Reference:https://github.com/imatix/zguide/raw/master/images/fig2.png

After successfully connected,REQ and REP can start to act like

pin-pong

1813年5月17⽇日星期五

Page 19: Introduction to ZeroMQ

REQuest-REPlyOnly suite for demonstrating simple program of network chatting room to your TA with limited condition: pin-pong action. lol

You can design your own transmit strategy when speed of network aren’t stable for your file-transfer application according the time of response-received from other side.

1913年5月17⽇日星期五

Page 20: Introduction to ZeroMQ

PUBlish-SUBscribePublisher

PUB

SUBSubscriber

bind

Connect Connect

SUBSubscriber

SUBSubscriber

Connect

update

2013年5月17⽇日星期五

Page 21: Introduction to ZeroMQ

PUBlish-SUBscribe

Scenario: News feeds

Must explicitly assign subscribe condition: zmq_setsockopt

Auto delivered if they are connected successfully

2113年5月17⽇日星期五

Page 22: Introduction to ZeroMQ

PipelineAlways synchronize workers to start

load balancing from vent. to worker

fair-queuing: Sink collect data from workers

Reference: https://github.com/imatix/zguide/raw/master/images/fig5.png

2213年5月17⽇日星期五

Page 23: Introduction to ZeroMQ

Pipeline scenarios

Supercomputing

Wireless sensor network

...etc

2313年5月17⽇日星期五

Page 24: Introduction to ZeroMQ

Dealer

enhanced REQ

no restrict behaviors of send and receive

Router

Prepend identity of originator to message before passing it to another application

2413年5月17⽇日星期五

Page 25: Introduction to ZeroMQ

Example of Router and Dealer

Reference: https://github.com/imatix/zguide/raw/master/images/fig17.png

2513年5月17⽇日星期五

Page 26: Introduction to ZeroMQ

More actors model

Router

Dealer

Push

Pull

Pair

I won’t explain details today

2613年5月17⽇日星期五

Page 27: Introduction to ZeroMQ

Features2713年5月17⽇日星期五

Page 29: Introduction to ZeroMQ

DistributedScalability

2913年5月17⽇日星期五

Page 30: Introduction to ZeroMQ

DistributedScalability

2913年5月17⽇日星期五

Page 31: Introduction to ZeroMQ

Sockets

IPC

Thread communication

TCP

Multicast

...etc

3013年5月17⽇日星期五

Page 32: Introduction to ZeroMQ

ZeroMQ CentralizedServer - REPly

Client - REQuest

Client - REQuest

3113年5月17⽇日星期五

Page 33: Introduction to ZeroMQ

AUto reconnect

First, clients issue request of connection

Later, server binds a port to reply the requests from clients

Centralize

3213年5月17⽇日星期五

Page 34: Introduction to ZeroMQ

AUto reconnect

First, clients issue request of connection

Later, server binds a port to reply the requests from clients

CentralizeStrange!

Not conventional

3213年5月17⽇日星期五

Page 35: Introduction to ZeroMQ

Demo

3313年5月17⽇日星期五

Page 36: Introduction to ZeroMQ

Code of REQ-REP

hwserver.rb

hwclient.rb

3413年5月17⽇日星期五

Page 37: Introduction to ZeroMQ

Demo REQ-REP

3513年5月17⽇日星期五

Page 38: Introduction to ZeroMQ

Code of PUB-SUB

wuserver.rb wuclient.rb

3613年5月17⽇日星期五

Page 39: Introduction to ZeroMQ

Demo PUB-SUB

3713年5月17⽇日星期五

Page 40: Introduction to ZeroMQ

Demo

Pipeline

taskvent.rb

taskwork.rb

tasksink.rb

3813年5月17⽇日星期五

Page 45: Introduction to ZeroMQ

Question?

4313年5月17⽇日星期五

Page 46: Introduction to ZeroMQ

Multi-players chat room?

Leave it to you :p

4413年5月17⽇日星期五

Page 47: Introduction to ZeroMQ

FAQ

Get peer list?

No

4513年5月17⽇日星期五

Page 48: Introduction to ZeroMQ

Notice

These slides has presented in micro session CNA@CCU 2013

If I forgot to give a credit to you via referring your content, I will append it to reference page as soon as you notify me about that. :)

4613年5月17⽇日星期五