Introduction to ZeroMQ - eSpace TechTalk

20
Introduction to ZeroMQ eSpace TechTalks @modsaid

description

A quick overview about zeroMQ as part of eSpace weekly techtalks

Transcript of Introduction to ZeroMQ - eSpace TechTalk

Page 1: Introduction to ZeroMQ - eSpace TechTalk

Introduction to ZeroMQ

eSpace TechTalks@modsaid

Page 2: Introduction to ZeroMQ - eSpace TechTalk

Outline

● Quick Definition

● Creators

● Why ØMQ?

● What the hell is it?

● Patterns

● Demos

● Should it be C?

● Discussion

Page 3: Introduction to ZeroMQ - eSpace TechTalk

Quick Definition

● ØMQ (aka ZeroMQ, 0MQ or ZMQ)

● a high-performance asynchronous messaging library

● aimed at use in scalable distributed or concurrent applications.

● It provides a message queue, but unlike message-oriented middleware, a ØMQ system can run without a dedicated message broker.

● The library is designed to have a familiar socket-style API.

Page 4: Introduction to ZeroMQ - eSpace TechTalk

Creators - Martin Sústrik

● Martin Sústrik (@sustrik)

● Expert in the field of messaging middle-ware

● Participated in the creation & implementation reference of AMQP standard.

● Founder of the ØMQ project.

● currently is working on integration of messaging technology with OS & Internet stack

Page 5: Introduction to ZeroMQ - eSpace TechTalk

Creators - Pieter Hintjens

● Belgian software developer, writer.

● Past president of the Foundation for a Free Information Infrastructure

● Author of Orielly ZeroMQ

● CEO or iMatix

Page 6: Introduction to ZeroMQ - eSpace TechTalk

Why ØMQ?

● Moore's Law means more moving pieces

● Cost of Connection is high

● Needed cheaper, fast and reliable connections

● Physics of Software Development

Page 7: Introduction to ZeroMQ - eSpace TechTalk

What the hell is it?

● Intelligent socket library for messaging

● Many kinds of connection patterns

● Multiplatform, multi-language (30+: ruby, C, C++, java, python, …. )

● Fast (8M msg/sec, 30usec latency)

● Small (20K lines of C++ code)

● Distributed

● Open source LGPL (large community)

Page 8: Introduction to ZeroMQ - eSpace TechTalk

What the hell is it? (2)

● Socket like API. But better than sockets

● Based on reactor pattern“Event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.”

Page 9: Introduction to ZeroMQ - eSpace TechTalk

Patterns

● Request – Reply

● Publish-Subscribe

● Push-Pull (pipeline)

● Exclusive Pair

Page 10: Introduction to ZeroMQ - eSpace TechTalk

Request-Reply Pattern

Page 11: Introduction to ZeroMQ - eSpace TechTalk

Publish-Subscribe Pattern

Page 12: Introduction to ZeroMQ - eSpace TechTalk

Pipeline Pattern

Page 13: Introduction to ZeroMQ - eSpace TechTalk

Demo

● HelloWorld req-rep

● Weather pub-sub

● Tasks workers (pipeline)

Page 14: Introduction to ZeroMQ - eSpace TechTalk

Use Case

● Centralized Logging for rails instances

“Several application servers, consolidated logs”

Page 15: Introduction to ZeroMQ - eSpace TechTalk

ØMQ Transports

● Threads in one process (inproc://)

● Processes on one box (ipc://)

● Processes on one network (tcp://)

● Multicast group (pgm://)

Page 16: Introduction to ZeroMQ - eSpace TechTalk

ØMQ Routing

● Round-robin (REQ, PUSH, DEALER)

● Multicast (PUB)

● Fair-queuing (REP, SUB, PULL, DEALER)

● Explicit addressing (ROUTER)

● Unicast (PAIR)

Page 17: Introduction to ZeroMQ - eSpace TechTalk

ØMQ Benefits

● Start with simple / fast language (Python)

● Move to faster language where needed (C)

● Run on arbitrary platforms (Windows, Android)

● Scale to arbitrary sizes (2 cores, 16 cores...)

● No per-core or per-seat licensing

● Easy to experiment and learn

Page 18: Introduction to ZeroMQ - eSpace TechTalk

AMQP vs ØMQ

● Centralized (like SVN)

● Family of messaging protocols used through implementations like RabbitMQ, Apache Qpid..

● Main use cases: transient pubsub distribution and reliable request-reply

● Dozens of pieces doing perhaps a hundred thousand messages per second

● Distributed (like git)

● Messaging library, and tools

● Covers transient pubsub, unreliable request-reply, pipeline, and peer-to-peer.

● Hundreds or thousands of pieces perhaps doing hundreds of millions of messages per second

Page 19: Introduction to ZeroMQ - eSpace TechTalk

Why should it have been C?

● C++ was chosen for STL, coding style, destructors, virtual functions

● 5 years old admission: poor choice

● Exception Handling guarantee not failing, but not undefined behavior

● Meant to be infrastructure

● Preventing undefined behavior more important

● More efficient compiled code

● System program

● Recent translation to C, nanomsg (not released yet)

Page 20: Introduction to ZeroMQ - eSpace TechTalk

References

● http://zguide.zeromq.org/page:all

● http://en.wikipedia.org/wiki/%C3%98MQ

● http://www.imatix.com/

● http://www.zeromq.org/docs:welcome-from-amqp

● http://www.rabbitmq.com/blog/tag/zeromq/

● http://www.250bpm.com/blog:4 (why it should've been C)

● http://nanomsg.org/ (C endeavor)

● http://www.zeromq.org/docs:labs

● http://www.slideshare.net/pieterh/overview-of-zeromq