Top Banner
You got ur Erlang in my Ruby Ezra Zygmuntowicz Join the nanite cloud if you have OSX: curl -O http://brainspl.at/ef.sh && sh ef.sh
34

Erlangfactory

May 12, 2015

Download

News & Politics

My talk on ruby, erlang, nanite, amqp and redis at the Erlang Factory conference
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Erlangfactory

You got ur Erlang in my Ruby

Ezra Zygmuntowicz

Join the nanite cloud if you have OSX:curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 2: Erlangfactory

Two Great tastes that go great together

Page 3: Erlangfactory

Erlangcurl -O http://brainspl.at/ef.sh && sh ef.sh

Page 4: Erlangfactory

ErlangPROS:

Fault TolerantDistributedActor ModelImmutable

ScalableConcurrency

Let it FailAwesome VM

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 5: Erlangfactory

ErlangCONS:

Unfamiliar SyntaxPrimitive

String handlingSlow(ish) IO

Much harder to find developers

PROS:Fault Tolerant

DistributedActor ModelImmutable

ScalableConcurrency

Let it FailAwesome VM

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 6: Erlangfactory

Rubycurl -O http://brainspl.at/ef.sh && sh ef.sh

Page 7: Erlangfactory

RubyPROS:Rapid

DevelopmentFamiliar Concise

SyntaxExcellent String

HandlingVery

ApproachableEasy to find developers

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 8: Erlangfactory

RubyCONS:

1024 open FD limit

No Multi-CoreHorrible GCNo Native Threads

Primadonnas in community :P

Creaky Interpreter

PROS:Rapid

DevelopmentFamiliar Concise

SyntaxExcellent String

HandlingVery

ApproachableEasy to find developers

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 9: Erlangfactory

What if we can combine the best of both?

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 10: Erlangfactory

Use Erlang for its strengths

Use Ruby for its strengths

MessagingNetworkingScalability

Distribution

Rapid DevelopmentDSL/concise Syntax

Ease of use/installation

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 11: Erlangfactory

Erlang VM

Page 12: Erlangfactory

NaniteLooks a lot like an exploded Erlang VM

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 13: Erlangfactory

RabbitMQ

6kloc of beautiful erlangmodels queues as processes

replicates routing info across clustered VMs

Single queue live on single vmAMQP Protocol(win!)

curl -O http://brainspl.at/ef.sh && sh ef.sh

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 14: Erlangfactory

AMQP Basics

The Trinity...

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 15: Erlangfactory

AMQP BasicsQueues:

curl -O http://brainspl.at/ef.sh && sh ef.sh

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 16: Erlangfactory

AMQP BasicsQueues:

Queues are FIFO buffers of messagesMessages consumed from the front of the queue

New messages are placed in the back of the queueQueues can be transient or persistent

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 17: Erlangfactory

AMQP BasicsExchanges:

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 18: Erlangfactory

AMQP BasicsExchanges:

Exchanges are where producers send messagesMultiple exchange types:

Direct, Fanout, TopicExchanges are routers with routing tables

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 19: Erlangfactory

AMQP BasicsBindings:

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 20: Erlangfactory

AMQP BasicsBindings:

Bindings are the ‘glue’ between exchanges and queuesBindings take exchange routing rules, apply filters

and push messages onto destination queues

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 22: Erlangfactory

Nanite AMQP overview

curl -O http://brainspl.at/ef.sh && sh ef.sh

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 23: Erlangfactory

Nanite Agents/Actorscurl -O http://brainspl.at/ef.sh && sh ef.sh

Page 24: Erlangfactory

Nanite Registration/Advertising

This actor will advertise

these services:/simple/echo/simple/time

And these tags:customer-42

urmomurdad

You can route requests based on services and tags

Page 25: Erlangfactory

Nanite StateAgent state can be stored replicated in memory in

the mappers.

Or for more scalable systems, state can be stored in a Redis DHT

We build an inverted index so agent lookup based on tags and services is just one set intersection away

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 26: Erlangfactory

Nanite Statenanite-foobar: 0.72 # load average or 'status'

s-nanite-foobar: { /foo/bar, /foo/nik } # a SET of the provided services

tg-nanite-foobar: { foo-42, some-tag } # a SET of the tags for this agent

t-nanite-foobar: 123456789 # unix timestamp of the last state update

# inverted indexes/foo/bar: { nanite-foobar, nanite-nickelbag, nanite-another } # redis SETsome-tag: { nanite-foobar, nanite-nickelbag, nanite-another }

Page 27: Erlangfactory

Securityrabbitmqctl set_permissions -p /nanite nanite "^nanite.*" ".*" ".*"

rabbitmqctl set_permissions -p /nanite mapper ".*" ".*" ".*"(only available in rabbitmq hg HEAD)

Secure SerializerPackets are encrypted and signed with public/

private keypairs(X.509)Certs are tied to a Nanite’s identity and the mappers have a Cert Store where they can dynamically look

up the proper keys to handle a packet

(Thanks for Raphael from RightScale for the Security code)

Page 28: Erlangfactory

Let’s see that demo

curl -O http://brainspl.at/ef.sh && sh ef.sh

Page 29: Erlangfactory

What did I make nanite for?

Page 30: Erlangfactory

Future Directions

• Use Rabbitmq patch(bug19230) to add ‘presence’ to the broker and get rid of ‘pings’

• Erlang agents/mappers

• Mappers have features that ‘should’ be in the broker, integrate what makes sense directly

Page 31: Erlangfactory

Future Directions

• Explore using Erlix for directly integrating ruby as an erlang node in the rabbit broker:

• http://github.com/KDr2/erlix

Page 32: Erlangfactory

Future Directions

• Explore creating an AQMP -> Couchdb query interface using the erlang AMQP client and the new native erlang couchdb client

Page 34: Erlangfactory

Questions?