RabbitMQ Data Ingestion at Craft Conf

117

Click here to load reader

description

Presentation about RabbitMQ and Federation

Transcript of RabbitMQ Data Ingestion at Craft Conf

Page 1: RabbitMQ Data Ingestion at Craft Conf

Building a Distributed Data Ingestion System

with RabbitMQAlvaro Videla - RabbitMQ

Page 2: RabbitMQ Data Ingestion at Craft Conf

Alvaro Videla

• Developer Advocate at Pivotal / RabbitMQ!

• Co-Author of RabbitMQ in Action!

• Creator of the RabbitMQ Simulator!

• Blogs about RabbitMQ Internals: http://videlalvaro.github.io/internals.html!

• @old_sound — [email protected] — github.com/videlalvaro

Page 3: RabbitMQ Data Ingestion at Craft Conf

About Me

Co-authored!!

RabbitMQ in Action!

http://bit.ly/rabbitmq

Page 4: RabbitMQ Data Ingestion at Craft Conf

About this Talk

• Exploratory Talk

• A ‘what could be done’ talk instead of ‘this is how you do it’

Page 5: RabbitMQ Data Ingestion at Craft Conf

Agenda

• Intro to RabbitMQ

• The Problem

• Solution Proposal

• Improvements

Page 6: RabbitMQ Data Ingestion at Craft Conf

Intermission

Page 7: RabbitMQ Data Ingestion at Craft Conf

Intermission

History Lessons

Page 8: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

Page 9: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

• I’m from Uruguay

Page 10: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

• I’m from Uruguay

• I live in Switzerland

Page 11: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

• I’m from Uruguay

• I live in Switzerland

• I’m in Hungary right now

Page 12: RabbitMQ Data Ingestion at Craft Conf

WHAT?

Page 13: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

Page 14: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

Switzerland World Cup - 1954

Page 15: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

Switzerland World Cup - 1954

Page 16: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection

Switzerland World Cup - 1954

Hungary 4 - Uruguay 2

Page 17: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection II

Tivadar Puskás

Telephone Switch Inventor

Page 18: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection III

Old Hungarian Alphabet

Page 19: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection III

Erlang

Page 20: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection III

As Neumann János Lajos said

Page 21: RabbitMQ Data Ingestion at Craft Conf

The Hungarian Connection III

As Neumann János Lajos said

Use Erlang

Page 22: RabbitMQ Data Ingestion at Craft Conf

What is RabbitMQ

Page 23: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ

Page 24: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ

Page 25: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ• Multi Protocol Messaging Server

Page 26: RabbitMQ Data Ingestion at Craft Conf

• Multi Protocol Messaging Server!• Open Source (MPL)

RabbitMQ

Page 27: RabbitMQ Data Ingestion at Craft Conf

• Multi Protocol Messaging Server!• Open Source (MPL)!• Polyglot

RabbitMQ

Page 28: RabbitMQ Data Ingestion at Craft Conf

• Multi Protocol Messaging Server!• Open Source (MPL)!• Polyglot!• Written in Erlang/OTP

RabbitMQ

Page 30: RabbitMQ Data Ingestion at Craft Conf

http://www.rabbitmq.com/community-plugins.html

Community Plugins

Page 31: RabbitMQ Data Ingestion at Craft Conf

Polyglot

Page 32: RabbitMQ Data Ingestion at Craft Conf

Polyglot

Page 33: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java

Page 34: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js

Page 35: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js!• Erlang

Page 36: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js!• Erlang!• PHP

Page 37: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js!• Erlang!• PHP!• Ruby

Page 38: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js!• Erlang!• PHP!• Ruby!• .Net

Page 39: RabbitMQ Data Ingestion at Craft Conf

Polyglot

• Java!• node.js!• Erlang!• PHP!• Ruby!• .Net!• Haskell

Page 40: RabbitMQ Data Ingestion at Craft Conf

Polyglot

Even COBOL!!!11

Page 41: RabbitMQ Data Ingestion at Craft Conf

Some users of RabbitMQ

Page 42: RabbitMQ Data Ingestion at Craft Conf

• Instagram

Some users of RabbitMQ

Page 43: RabbitMQ Data Ingestion at Craft Conf

• Instagram!• Indeed.com

Some users of RabbitMQ

Page 44: RabbitMQ Data Ingestion at Craft Conf

• Instagram!• Indeed.com!• Telefonica

Some users of RabbitMQ

Page 45: RabbitMQ Data Ingestion at Craft Conf

• Instagram!• Indeed.com!• Telefonica!• Mercado Libre

Some users of RabbitMQ

Page 46: RabbitMQ Data Ingestion at Craft Conf

• Instagram!• Indeed.com!• Telefonica!• Mercado Libre!• NHS

Some users of RabbitMQ

Page 47: RabbitMQ Data Ingestion at Craft Conf

• Instagram!• Indeed.com!• Telefonica!• Mercado Libre!• NHS!• Mozilla

Some users of RabbitMQ

Page 48: RabbitMQ Data Ingestion at Craft Conf

The New York Times on RabbitMQ

This architecture - Fabrik - has dozens of RabbitMQ instances spread across 6 AWS zones in Oregon and Dublin.

Upon launch today, the system autoscaled to ~500,000 users. Connection times remained flat at ~200ms.

http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2014-January/032943.html

Page 49: RabbitMQ Data Ingestion at Craft Conf

http://www.rabbitmq.com/download.html

Unix - Mac - Windows

Page 50: RabbitMQ Data Ingestion at Craft Conf

Messaging with RabbitMQ

A demo with the RabbitMQ Simulator

https://github.com/RabbitMQSimulator/RabbitMQSimulator

Page 51: RabbitMQ Data Ingestion at Craft Conf

http://tryrabbitmq.com

Page 52: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Simulator

Page 53: RabbitMQ Data Ingestion at Craft Conf

The Problem

Page 54: RabbitMQ Data Ingestion at Craft Conf

Distributed Application

App

App

App

App

Page 55: RabbitMQ Data Ingestion at Craft Conf

Distributed Application

App

App

App

App

Page 56: RabbitMQ Data Ingestion at Craft Conf

ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); !

Connection connection = factory.newConnection(); !

Channel channel = connection.createChannel();

Data ProducerObtain a Channel

Page 57: RabbitMQ Data Ingestion at Craft Conf

channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);

Data Producer

Declare an Exchange

Page 58: RabbitMQ Data Ingestion at Craft Conf

String message = "Hello Federation!"; channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());

Data Producer

Publish a message

Page 59: RabbitMQ Data Ingestion at Craft Conf

ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); !

Connection connection = factory.newConnection(); !

Channel channel = connection.createChannel();

Data ConsumerObtain a Channel

Page 60: RabbitMQ Data Ingestion at Craft Conf

channel.queueDeclare(QUEUE_NAME, true, false, false, null); channel.exchangeDeclare(EXCHANGE_NAME, "direct", true); channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");

Data ConsumerDeclare Queue and bind it

Page 61: RabbitMQ Data Ingestion at Craft Conf

QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, false, consumer);

Data ConsumerStart a consumer

Page 62: RabbitMQ Data Ingestion at Craft Conf

while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println("Received '" + message + "'"); !

channel.basicAck( delivery.getEnvelope(). getDeliveryTag(), false); }

Data ConsumerProcess messages

Page 63: RabbitMQ Data Ingestion at Craft Conf

Ad-hoc solution

Page 64: RabbitMQ Data Ingestion at Craft Conf

A process that replicates data to the remote server

Page 65: RabbitMQ Data Ingestion at Craft Conf

Possible issues• Remote server is offline

• Prevent unbounded local buffers

• Prevent message loss

• Prevent unnecessary message replication

• No need for those messages on remote server

• Messages that became stale

Page 66: RabbitMQ Data Ingestion at Craft Conf

Can we do better?

Page 67: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

Page 68: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation• Supports replication across different administrative domains

• Supports mix of Erlang and RabbitMQ versions

• Supports Network Partitions

• Specificity - not everything has to be federated

Page 69: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

Page 70: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

Page 71: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

Page 72: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

• It’s a RabbitMQ Plugin

Page 73: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

• It’s a RabbitMQ Plugin

• Internally uses Queues and Exchanges Decorators

Page 74: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

• It’s a RabbitMQ Plugin

• Internally uses Queues and Exchanges Decorators

• Managed using Parameters and Policies

Page 75: RabbitMQ Data Ingestion at Craft Conf

Enabling the Plugin

rabbitmq-plugins enable rabbitmq_federation

Page 76: RabbitMQ Data Ingestion at Craft Conf

Enabling the Plugin

rabbitmq-plugins enable rabbitmq_federation

rabbitmq-plugins enable rabbitmq_federation_management

Page 77: RabbitMQ Data Ingestion at Craft Conf

Federating an Exchange

rabbitmqctl set_parameter federation-upstream my-upstream \ ‘{“uri":"amqp://server-name","expires":3600000}'

Page 78: RabbitMQ Data Ingestion at Craft Conf

Federating an Exchange

rabbitmqctl set_parameter federation-upstream my-upstream \ ‘{“uri":"amqp://server-name","expires":3600000}' !

rabbitmqctl set_policy --apply-to exchanges federate-me "^amq\." \ '{"federation-upstream-set":"all"}'

Page 79: RabbitMQ Data Ingestion at Craft Conf

Federating an Exchange

Page 80: RabbitMQ Data Ingestion at Craft Conf

Configuring Federation

Page 81: RabbitMQ Data Ingestion at Craft Conf

Config Optionsrabbitmqctl set_parameter federation-upstream \ name ‘json-object’

Page 82: RabbitMQ Data Ingestion at Craft Conf

Config Optionsrabbitmqctl set_parameter federation-upstream \ name ‘json-object’ !

json-object: { ‘uri’: ‘amqp://server-name/’, ‘prefetch-count’: 1000, ‘reconnect-delay’: 1, ‘ack-mode’: on-confirm }

http://www.rabbitmq.com/federation-reference.html

Page 83: RabbitMQ Data Ingestion at Craft Conf

Prevent unbound buffers

expires: N // ms. message-ttl: N // ms.

Page 84: RabbitMQ Data Ingestion at Craft Conf

Prevent message forwarding

max-hops: N

Page 85: RabbitMQ Data Ingestion at Craft Conf

Speed vs No Message Loss

ack-mode: on-confirm ack-mode: on-publish

ack-mode: no-ack

Page 86: RabbitMQ Data Ingestion at Craft Conf

AMQP URI:

amqp://user:pass@host:10000/vhost

http://www.rabbitmq.com/uri-spec.html

Page 87: RabbitMQ Data Ingestion at Craft Conf

Config can be applied via

• CLI using rabbitmqctl

• HTTP API

• RabbitMQ Management Interface

Page 88: RabbitMQ Data Ingestion at Craft Conf

RabbitMQ Federation

Page 89: RabbitMQ Data Ingestion at Craft Conf

Scaling the Setup

Page 90: RabbitMQ Data Ingestion at Craft Conf

The Problem

Page 91: RabbitMQ Data Ingestion at Craft Conf

The Problem

• Queues contents live in the node where the Queue was declared

Page 92: RabbitMQ Data Ingestion at Craft Conf

The Problem

• Queues contents live in the node where the Queue was declared

• A cluster can access the queue from every connected node

Page 93: RabbitMQ Data Ingestion at Craft Conf

The Problem

• Queues contents live in the node where the Queue was declared

• A cluster can access the queue from every connected node

• Queues are an Erlang process (tied to one core)

Page 94: RabbitMQ Data Ingestion at Craft Conf

The Problem

• Queues contents live in the node where the Queue was declared

• A cluster can access the queue from every connected node

• Queues are an Erlang process (tied to one core)

• Adding more nodes doesn’t really help

Page 95: RabbitMQ Data Ingestion at Craft Conf

Enter Sharded Queues

Page 96: RabbitMQ Data Ingestion at Craft Conf

Enter Sharded Queues

Page 97: RabbitMQ Data Ingestion at Craft Conf

Pieces of the Puzzle

• modulo hash exchange (consistent hash works as well)

• good ol’ queues

Page 98: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

Page 99: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

Page 100: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

Page 101: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

Page 102: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

• Declare Queues with name: nodename.queuename.index

Page 103: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

• Declare Queues with name: nodename.queuename.index

• Bind the queues to a consistent hash exchange

Page 104: RabbitMQ Data Ingestion at Craft Conf

Sharded Queues

• Declare Queues with name: nodename.queuename.index

• Bind the queues to a partitioner exchange

• Transparent to the consumer (virtual queue name)

Page 105: RabbitMQ Data Ingestion at Craft Conf

We need more scale!

Page 106: RabbitMQ Data Ingestion at Craft Conf

Federated Queues

Page 107: RabbitMQ Data Ingestion at Craft Conf

Federated Queues

• Load-balance messages across federated queues

• Only moves messages when needed

Page 108: RabbitMQ Data Ingestion at Craft Conf

Federating a Queue

rabbitmqctl set_parameter federation-upstream my-upstream \ ‘{“uri":"amqp://server-name","expires":3600000}'

Page 109: RabbitMQ Data Ingestion at Craft Conf

Federating a Queue

rabbitmqctl set_parameter federation-upstream my-upstream \ ‘{“uri":"amqp://server-name","expires":3600000}' !

rabbitmqctl set_policy --apply-to queues federate-me "^images\." \ '{"federation-upstream-set":"all"}'

Page 110: RabbitMQ Data Ingestion at Craft Conf

With RabbitMQ we can

Page 111: RabbitMQ Data Ingestion at Craft Conf

With RabbitMQ we can

• Ingest data using various protocols: AMQP, MQTT and STOMP

Page 112: RabbitMQ Data Ingestion at Craft Conf

With RabbitMQ we can

• Ingest data using various protocols: AMQP, MQTT and STOMP

• Distribute that data globally using Federation

Page 113: RabbitMQ Data Ingestion at Craft Conf

With RabbitMQ we can

• Ingest data using various protocols: AMQP, MQTT and STOMP

• Distribute that data globally using Federation

• Scale up using Sharding

Page 114: RabbitMQ Data Ingestion at Craft Conf

With RabbitMQ we can

• Ingest data using various protocols: AMQP, MQTT and STOMP

• Distribute that data globally using Federation

• Scale up using Sharding

• Load balance consumers with Federated Queues

Page 115: RabbitMQ Data Ingestion at Craft Conf

Credits

world map: wikipedia.org

federation diagrams: rabbitmq.com

Page 116: RabbitMQ Data Ingestion at Craft Conf

Questions?

Page 117: RabbitMQ Data Ingestion at Craft Conf

ThanksAlvaro Videla - @old_sound