ZeroMQ

zhesto 3,750 views 54 slides May 28, 2012
Slide 1
Slide 1 of 54
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54

About This Presentation

Using 0mq from Ruby.


Slide Content

http://zero.mq/

A ØMQ socket is what you get when
you take a normal TCP socket, inject
it with a mix of radioactive isotopes
stolen from a secret Soviet atomic
research project, bombard it with
1950-era cosmic rays, and put it into
the hands of a drug-addled comic
book author with a badly-disguised
fetish for bulging muscles clad in
spandex. Yes, ØMQ sockets are the
world-saving superheros of the
networking world.

Problem

How to
easy connect
any code to any code,
anywhere

Existing solutions

Connect
•In-process in-proc://some-point
•Unix sockets ipc://some/pipe
•BSD sockets tcp://0.0.0.0:1234
•Others multicast (PGM) ...

BSD Sockets

BSD
TCP
* Images by Tenouk
Protocols

BSD
TCP
UDP
* Images by Tenouk
Protocols

•New/Exit - socket() , close()
•Configure - setsockopt()
•Connect - bind() , connect()
•Use - send() , recv()
Sockets
BSD

Problems
BSD
•Need to choice of transport
•Stream (TCP) , datagram (UDP)
•Peer-2-Peer connections

zguide.zero.mq

A ØMQ socket is what you get when
you take a normal TCP socket, inject
it with a mix of radioactive isotopes
stolen from a secret Soviet atomic
research project, bombard it with
1950-era cosmic rays, and put it into
the hands of a drug-addled comic
book author with a badly-disguised
fetish for bulging muscles clad in
spandex. Yes, ØMQ sockets are the
world-saving superheros of the
networking world.

in a Hundred Words
ØMQ (ZeroMQ, 0MQ, zmq) looks like an embeddable
networking library but acts like a concurrency
framework.
It gives you sockets that carry whole messages across
various transports like in-process, inter-process, TCP, and
multicast.
You can connect sockets N-to-N with patterns like
fanout, pub-sub, task distribution, and request-reply. It's fast
enough to be the fabric for clustered products. Its
asynchronous I/O model gives you scalable multicore
applications, built as asynchronous message-processing tasks.
It has a score of language APIs and runs
on most operating systems.
ØMQ is from iMatix and is LGPL open source.

Many languages
* Images by iMatrix

Sockets
•Well known API
•Messages oriented
•Transport agnostic
•Socket-level topology

Well known API

Sockets
•New/Exit - socket()
•Configure - setsockopt()
•Connect - bind()
•Use - send() , recv()
BSD

Sockets
•New/Exit - zmq_socket()
•Configure - zmq_setsockopt()
•Connect - zmq_bind()
•Use - zmq_send() , zmq_recv()

Hello world (server)

Hello world (client)

Message oriented

Message oriented
Receive
Send

Various transports

Various transports
•req.bind(‘inproc://some/pipe’)
•req.bind(‘ipc://some/pipe’)
•req.bind(’tcp://127.0.0.1:5555’)

Patterns
Socket level topology

Request - Reply
* Images by iMatrix

Publish - Subscribe
* Images by iMatrix

Parallel tasks
* Images by iMatrix

Demo

Scale

Start small
* Images by iMatrix

Bigger
* Images by iMatrix

And bigger...
* Images by iMatrix

Devices
* Images by iMatrix
Device

QUEUE
* Images by iMatrix

Demo

Implementation

Ruby-FFI
Foreign Function Interface

Ruby-FFI

Ruby-FFI (Win)

Why FFI?
•Debian: no need from *-dev
•Multi-platform
•Easy to read (Ruby, not C)

Projects
http://zeromq.org/docs:labs

http://mongrel2.org

Evolution
HTTP
Net
App
HTTP
Net
App
HTTP
Net
App
Webrick Mongrel Thin

Evolution
HTTP
Net
App
Mongrel2

Mongrel2
0mq
Handler
Handler
Handler
Responses
Requests
Push/Pull Pub/Sub

Demo

Future
•Part of Linux kernel
•http://www.crossroads.io/
•zerocloud ?

Thank you!