Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ØMQ and Perl

Anthony
November 14, 2013

ØMQ and Perl

Introduction to ØMQ, how to use it in Perl, and some patterns you'll need when building an application.

Anthony

November 14, 2013
Tweet

More Decks by Anthony

Other Decks in Programming

Transcript

  1. A better socket • Abstracts connection boilerplate • Gracefully handles

    connections • Messages don’t change during send
  2. A better message queue • Queues packets being sent or

    received • One-way and two-way message patterns for concurrency • Decentralized
  3. When to use ØMQ? • Replacing an RPC or RESTful

    API • Asynchronous tasks model with workers • Cross language support is needed • Just need to write a socket
  4. ØMQ isn’t a replacement for • A client-facing HTTP API

    • Low latency sockets • Job queues
  5. Paired socket types • REQ/REP - send packet, expect response

    • PUSH/PULL - send/receive packet, no response • PUB/SUB - similar to pull, packet duplicated to all clients • ROUTER/DEALER - accumulate and distribute packets • REQ/ROUTER and DEALER/REP - load balancing
  6. Multipart messages • Message can be grouped for throughput •

    Queues in memory • Won’t send automatically • Delivers all or none
  7. Messages are strings • ØMQ knows nothing about your data

    • Data is a string and string length • Optionally use a serializer
  8. Queue HWM (High Water Mark) • Each socket has a

    HWM • Sockets have send and/or receive buffers • When the HWM is reached, sockets may block or drop • ØMQ v2 HWM is infinite • ØMQ v3 HWM is 1000 messages
  9. Socket reliability • Protect against socket failure • Poll receiving

    socket instead of blocking • Resend request after timeout, abandon if still no replies
  10. Polling sockets • Not blocking on receive • Can poll

    on multiple sockets • On socket receive, execute callback
  11. Cleaning up • Set the linger option on sockets as

    they are closed • Sockets that aren’t flushed cause the context to hang