SlideShare une entreprise Scribd logo
1  sur  34
Build reliable, traceable,
distributed systems with
ZeroMQ
PYCON2012
@jpetazzo
@dot_cloud
Outline
● Who we are
● Quick tour of ZeroRPC features
● Implementation overview
Introduction: why?
● We are running a PAAS:
we deploy, monitor, and scale your apps
(in the Cloud!)
● Many moving parts
● ... On a large distributed cluster
API endpoint Users (auth)
CLI
Formation
(analyzes stack)
Uploader
(code store)
Containers
(intances)
Deployments
(services)
Cluster Node
Cluster Node
Cluster Node
Cluster Node Host Info
VHosts
(HTTP)
NATS
(TCP/UDP)
Load
Balancer
Load
Balancer
Logger
Metrics
Dashboard
Internal tools
dotCloud architecture (simplified) — components, servers, things receiving data from everything else, me
Our requirements (easy)
● We want to be able to expose arbitrary code,
with minimal modification (if any)
If we can do import foo; foo.bar(42),
we want to be able to do foo=RemoteService(...) ;
foo.bar(42)
● We want a self-documented system
We want to see methods, signatures, docstrings, without
opening the code of the remote service, or relying on
(always out-dated) documentation
Our requirements (harder)
● We want to propagate exceptions properly
● We want to be language-agnostic
● We want to be brokerless, highly available,
fast, and support fan-in/fan-out topologies
(Not necessarily everything at the same time!)
● We want to trace & profile nested calls
Which call initiated the subcall which raised SomeException?
Which subcall of this complex call causes it to take
forever?
Why not {x} ?
● x=HTTP
o too much overhead for some use-cases
(logs and metrics)
o continuous stream of updates requires extra work
(chunked encoding, websockets...)
o asynchronous notification requires extra work
(long polling, websockets...)
o fan-out topology requires extra work
(implementing some kind of message queue)
● x=AMQP (or similar)
o too much overhead for some use-cases
What we came up with
ZeroRPC!
● Based on ZeroMQ and MessagePack
● Supports everything we needed!
● Multiple implementations
o Internal "reference" implementation in Python
o Public "alternative" implementation with gevents
o Internal Node.js implementation (so-so)
Example: unmodified
code
Expose the "urllib" module over RPC:
$ zerorpc-client --server --bind tcp://0:1234 urllib
Yup. That's it.
There is now something listening on TCP port
1234, and exposing the Python "urllib"
module.
Example: calling code
From the command line (for testing):
$ zerorpc-client tcp://0:1234 quote "hello pycon"
"hello%20pycon"
From Python code:
>>> import zerorpc
>>> remote_urllib = zerorpc.Client( )
>>> remote_urllib.connect('tcp://0:1234')
>>> remote_urllib.quote('hello pycon')
'hello%20pycon'
Example: introspection
We can list methods:
$ zerorpc-client tcp://localhost:1234 | grep ^q
quote quote('abc def') -> 'abc%20def'
quote_plus Quote the query fragment of a URL; replacing ' ' with '+'
We can see signatures and docstrings:
$ zerorpc-client tcp://localhost:1234 quote_plus - ?
quote_plus(s, safe='')
Quote the query fragment of a URL; replacing ' ' with '+'
Example: exceptions
$ zerorpc-client tcp://localhost:1234 quote_plus
Traceback (most recent call last): File
"/home/jpetazzo/.virtualenvs/dotcloud_develop/bin/zerorpc-client", line 131, in <module>
main()
File "/home/jpetazzo/.virtualenvs/dotcloud_develop/bin/zerorpc-client", line 127, in main
pprint(client(args.command,*parameters))
File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 362, in __call__
return self.recv()
File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 243, in recv
ret = self.handler(headers, method, *args)
File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 323, in handle_result
raise eTypeError: quote( ) takes at least 1 argument (0 given)
Example: load balancing
Start a load balancing hub:
$ cat foo.yml
in: "tcp://*:1111"
out: "tcp://*:2222"
type: queue
$ zerohub.py foo.yml
Start (at least) one worker:
$ zerorpc-client --server tcp://localhost:2222 urllib
Now connect to the "in" side of the hub:
$ zerorpc-client tcp://localhost:1111
Example: high availability
Start a local HAProxy in TCP mode, dispatching requests
to 2 or more remote services or hubs:
$ cat haproxy.cfg
listen zerorpc 0.0.0.0:1111
mode tcp
server backend_a localhost:2222 check
server backend_b localhost:3333 check
$ haproxy -f haproxy.cfg
Start (at least) one backend:$ zerorpc-client --server --bind
tcp://0:2222 urllib
Now connect to HAProxy:$ zerorpc-client tcp://localhost:1111
Non-Example: PUB/SUB
(not in public repo—yet)
● Broadcast a message to a group of nodes
o But if a node leaves and rejoins, he'll lose messages
● Send a continuous stream of information
o But if a speaker or listener leaves and rejoins...
You generally don't want to do this!
Better pattern: ZeroRPC streaming with
gevents
Example: streaming
● Server code returns an list iterator
● Client code gets an list iterator
● Small messages, high latency? No problem!
o Server code will pre-push elements
o Client code will notify server if pipeline runs low
● Huge messages? No problem!
o Big data sets can be nicely chunked
o They don't have to fit entirely in memory
o Don't worry about timeouts anymore
● Also supports long polling
Example: tracing
(not in public repo—yet)
$ dotcloud --trace alias add sushiblog.web www.deliciousrawfish.com
TraceID: 48aca4f4-75d5-40f2-b5bd-73c40ca40980Ok. Now please add the following DNS record:
www.deliciousrawfish.com. IN CNAME gateway.dotcloud.com.
$ dotcloud-tracedump 48aca4f4-75d5-40f2-b5bd-73c40ca40980[2012-03-0723:56:17.759738] uwsgi@api ---
run_command ---> api_00@zeroworkers(lag: 1ms | exec: 98ms)
[2012-03-07 23:56:17.770432] api_00@zeroworkers --- track ---> mixpanel_00@zeroworkers (lag: 1ms | exec: 70ms)
[2012-03-07 23:56:17.771264] api_00@zeroworkers --- km_track ---> mixpanel_01@zeroworkers (lag: 1ms | exec: 71ms)
[2012-03-07 23:56:17.771994] api_00@zeroworkers--- km_track ---> mixpanel_02@zeroworkers (lag: 1ms | exec: 71ms)
[2012-03-07 23:56:17.773041] api_00@zeroworkers--- record_event ---> users-events@users (lag: 0ms | exec: 0ms)
[2012-03-07 23:56:17.774972] api_00@zeroworkers --- info (pending) ---> formation-in [Not Received]
[2012-03-07 23:56:17.783590] api_00@zeroworkers --- info (pending) ---> formation-in [Not Received]
[2012-03-07 23:56:17.830107] api_00@zeroworkers --- add_alias ---> deployments_04@deployments (lag: 0ms | exec: 27ms)
[2012-03-07 23:56:17.831453] deployments_04@deployments --- exists_frontend ---> vhosts@vhosts (lag: 0ms | exec: 4ms)
[2012-03-07 23:56:17.836288] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms)
[2012-03-07 23:56:17.837370] deployments_04@deployments --- exists ---> vhosts@vhosts (lag: 0ms | exec: 1ms)
[2012-03-07 23:56:17.838733] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms)
[2012-03-07 23:56:17.840068] deployments_04@deployments --- add_frontend ---> vhosts@vhosts (lag: 0ms | exec: 15ms)
[2012-03-07 23:56:17.856166] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms)
[2012-03-07 23:56:17.857647] deployments_04@deployments --- OK ---> api_00@zeroworkers(lag: 0ms | exec: 0ms)
[2012-03-07 23:56:17.859824] api_00@zeroworkers --- OK ---> uwsgi@api (lag: 0ms | exec: 0ms)
Implementation details
This will be useful if...
● You think you might want to use ZeroRPC
● You think you might want to hack ZeroRPC
● You want to reimplement something similar
● You just happen to love distributed systems
ØMQ
● Sockets on
steroidshttp://zguide.zeromq.org/page:all
● Handles (re)connections for us
● Works over regular TCP
● Also has superfast ipc:// and inproc://
● Different patterns:
o REQ/REP (basic, synchronous RPC call +
response)
o PUB/SUB (shout and listen to streams of events)
o PUSH/PULL (load balance or collect messages)
o DEALER/ROUTER (REQ/REP with routing)
Serialization:
MessagePack
In our tests, msgpack is more efficient than
JSON, BSON, YAML:
● 20-50x faster
● serialized output is 2x smaller or better
$ pip install msgpack-python
>>> import msgpack
>>> bytes = msgpack.dumps(data)
Wire format
Request: (headers, method_name, args)
● headers dict
o no mandatory header
o carries the protocol version number
o used for tracing in our in-house version
● args
o list of arguments
o no named parameters
Response: (headers, ERR|OK|STREAM, value)
Timeouts
● ØMQ does not detect disconnections
(or rather, it works hard to hide them)
● You can't know when the remote is gone
● Original implementation: 30s timeout
● Published implementation: heartbeat
Introspection
● Expose a few special calls:
o _zerorpc_list to list calls
o _zerorpc_name to know who you're talking to
o _zerorpc_ping (redundant with the previous one)
o _zerorpc_help to retrieve the docstring of a call
o _zerorpc_args to retrieve the argspec of a call
o _zerorpc_inspect to retrieve everything at once
● Introspection + service discovery = WIN
Naming
● Published implementation does not include
any kind of naming/discovery
● In-house version uses a flat YAML file,
mapping service names to ØMQ addresses
and socket types
● In progress: use DNS records
o SRV for host+port
o TXT for ØMQ socket type (not sure about this!)
● In progress: registration of services
o Majordomo protocol
Security: there is none
● No security at all in ØMQ
o assumes that you are on a private, internal network
● If you need to run "in the wild", use SSL:
o bind ØMQ socket on localhost
o run stunnel (with client cert verification)
● In progress: authentication layer
● dotCloud API is actually ZeroRPC,
exposed through a HTTP/ZeroRPC gateway
● In progress: standardization of this gateway
Tracing (not published
yet)
● Initial implementation during a hack day
o bonus: displays live latency and request rates,
using http://projects.nuttnet.net/hummingbird/
o bonus: displays graphical call flow,
using http://raphaeljs.com/
o bonus: send exceptions to airbrake/sentry
● Refactoring in progress, to "untie" it from the
dotCloud infrastructure and Open Source it
How it works: all calls and responses are
logged to a central place, along with a
trace_id unique to each sequence of calls.
Tracing: trace_id
● Each call has a trace_id
● The trace_id is propagated to subcalls
● The trace_id is bound to a local context
(think thread local storage)
● When making a call:
o if there is a local trace_id, use it
o if there is none ("root call"), generate one (GUID)
● trace_id is passed in all calls and responses
Note: this is not (yet) in the github repository
Tracing: trace collection
● If a message (sent or received) has a
trace_id, we send out the following things:
o trace_id
o call name (or, for return values, OK|ERR+exception)
o current process name and hostname
o timestamp
Internal details: the collection is built on top of
the standard logging module.
Tracing: trace storage
● Traces are sent to a Redis key/value store
o each trace_id is associated with a list of traces
o we keep some per-service counters
o Redis persistence is disabled
o entries are given a TTL so they expire automatically
o entries were initially JSON (for easy debugging)
o ... then "compressed" with msgpack to save space
o approximately 16 GB of traces per day
Internal details: the logging handler does not talk directly to
Redis; it sends traces to a collector (which itself talks to
Redis).
The problem with being
synchronous
● Original implementation was synchronous
● Long-running calls blocked the server
● Workaround: multiple workers and a hub
● Wastes resources
● Does not work well for very long calls
o Deployment and provisioning of new cluster nodes
o Deployment and scaling of user apps
Note: this is not specific to ZeroRPC
First shot at
asynchronicity
● Send asynchronous events & setup
callbacks
● "Please do foo(42) and send the result to this
other place once you're done"
● We tried this. We failed.
o distributed spaghetti code
o trees falling in the forest with no one to hear them
● Might have worked better if we had...
o better support in the library
o better naming system
o something to make sure that we don't lose calls
Gevent to the rescue!
● Write synchronous code
(a.k.a. don't rewrite your services)
● Uses coroutines to achieve concurrency
● No fork, no threads, no problems
● Monkey patch of the standard library
(to replace blocking calls with async
versions)
● Achieve "unlimited" concurrency server-side
The version published on github uses gevent.
Show me the code!
https://github.com/dotcloud/zerorpc-python
$ pip install git+git://github.com/dotcloud/zerorpc-python.git
Has: zerorpc module, zerorpc-client helper,
exception propagation, gevent integration
Doesn't have: tracing, naming, helpers for
PUB/SUB & PUSH/PULL, authentication
Questions?
Thanks!

Contenu connexe

Tendances

系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言鍾誠 陳鍾誠
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commandsSagar Kumar
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringAnne Nicolas
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at NetflixBrendan Gregg
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsJames Dennis
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecturehugo lu
 
Linux interview questions and answers
Linux interview questions and answersLinux interview questions and answers
Linux interview questions and answersGanapathi Raju
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) Johnny Sung
 
The basic concept of Linux FIleSystem
The basic concept of Linux FIleSystemThe basic concept of Linux FIleSystem
The basic concept of Linux FIleSystemHungWei Chiu
 
Demystify eBPF JIT Compiler
Demystify eBPF JIT CompilerDemystify eBPF JIT Compiler
Demystify eBPF JIT CompilerNetronome
 
Shell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaShell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaEdureka!
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemSadia Bashir
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 

Tendances (20)

U boot-boot-flow
U boot-boot-flowU boot-boot-flow
U boot-boot-flow
 
系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Kernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uringKernel Recipes 2019 - Faster IO through io_uring
Kernel Recipes 2019 - Faster IO through io_uring
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at Netflix
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
Linux interview questions and answers
Linux interview questions and answersLinux interview questions and answers
Linux interview questions and answers
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
 
The basic concept of Linux FIleSystem
The basic concept of Linux FIleSystemThe basic concept of Linux FIleSystem
The basic concept of Linux FIleSystem
 
Demystify eBPF JIT Compiler
Demystify eBPF JIT CompilerDemystify eBPF JIT Compiler
Demystify eBPF JIT Compiler
 
Nmap
NmapNmap
Nmap
 
Shell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaShell Scripting Tutorial | Edureka
Shell Scripting Tutorial | Edureka
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
SystemV vs systemd
SystemV vs systemdSystemV vs systemd
SystemV vs systemd
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 

En vedette

Software Architecture over ZeroMQ
Software Architecture over ZeroMQSoftware Architecture over ZeroMQ
Software Architecture over ZeroMQpieterh
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQfcrippa
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQpieterh
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQpieterh
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characterspieterh
 
Switch or broker
Switch or brokerSwitch or broker
Switch or brokerpieterh
 
Revolutionary Open Source
Revolutionary Open SourceRevolutionary Open Source
Revolutionary Open Sourcepieterh
 
Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012pieterh
 
Git Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, ScalableGit Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, Scalablepieterh
 
Social architecture-101
Social architecture-101Social architecture-101
Social architecture-101pieterh
 
Fosdem 2009
Fosdem 2009Fosdem 2009
Fosdem 2009pieterh
 
Scala and ZeroMQ: Events beyond the JVM
Scala and ZeroMQ: Events beyond the JVMScala and ZeroMQ: Events beyond the JVM
Scala and ZeroMQ: Events beyond the JVMRUDDER
 
ZeroMQ e Redis: soluzioni open source per l'integrazione di componenti
ZeroMQ e Redis: soluzioni open source per l'integrazione di componentiZeroMQ e Redis: soluzioni open source per l'integrazione di componenti
ZeroMQ e Redis: soluzioni open source per l'integrazione di componentiMatteo Fortini
 
RestMS Introduction
RestMS IntroductionRestMS Introduction
RestMS Introductionpieterh
 
Introduction to ZeroMQ
Introduction to ZeroMQIntroduction to ZeroMQ
Introduction to ZeroMQYiHung Lee
 
Zmq in context of openstack
Zmq in context of openstackZmq in context of openstack
Zmq in context of openstackYatin Kumbhare
 
Design Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsDesign Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsEdureka!
 

En vedette (20)

Software Architecture over ZeroMQ
Software Architecture over ZeroMQSoftware Architecture over ZeroMQ
Software Architecture over ZeroMQ
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQ
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQ
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQ
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characters
 
Switch or broker
Switch or brokerSwitch or broker
Switch or broker
 
Revolutionary Open Source
Revolutionary Open SourceRevolutionary Open Source
Revolutionary Open Source
 
Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012
 
Git Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, ScalableGit Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, Scalable
 
Social architecture-101
Social architecture-101Social architecture-101
Social architecture-101
 
Fosdem 2009
Fosdem 2009Fosdem 2009
Fosdem 2009
 
Scala and ZeroMQ: Events beyond the JVM
Scala and ZeroMQ: Events beyond the JVMScala and ZeroMQ: Events beyond the JVM
Scala and ZeroMQ: Events beyond the JVM
 
Ømq & Services @ Chartboost
Ømq & Services @ ChartboostØmq & Services @ Chartboost
Ømq & Services @ Chartboost
 
ZeroMQ e Redis: soluzioni open source per l'integrazione di componenti
ZeroMQ e Redis: soluzioni open source per l'integrazione di componentiZeroMQ e Redis: soluzioni open source per l'integrazione di componenti
ZeroMQ e Redis: soluzioni open source per l'integrazione di componenti
 
RestMS Introduction
RestMS IntroductionRestMS Introduction
RestMS Introduction
 
Introduction to ZeroMQ
Introduction to ZeroMQIntroduction to ZeroMQ
Introduction to ZeroMQ
 
Zmq in context of openstack
Zmq in context of openstackZmq in context of openstack
Zmq in context of openstack
 
Design Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsDesign Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design Problems
 

Similaire à Build reliable, traceable, distributed systems with ZeroMQ

Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015Hiroshi Ota
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 
From nothing to Prometheus : one year after
From nothing to Prometheus : one year afterFrom nothing to Prometheus : one year after
From nothing to Prometheus : one year afterAntoine Leroyer
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server InternalsPraveen Gollakota
 
Infrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using PrometheusInfrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using PrometheusMarco Pas
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a gamejackpot201
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commandsRishu Seth
 
CEPH中的QOS技术
CEPH中的QOS技术CEPH中的QOS技术
CEPH中的QOS技术suncbing1
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauCeph Community
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterAnne Nicolas
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....Sadia Textile
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Brian Brazil
 
202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUPRonald Hsu
 

Similaire à Build reliable, traceable, distributed systems with ZeroMQ (20)

Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
From nothing to Prometheus : one year after
From nothing to Prometheus : one year afterFrom nothing to Prometheus : one year after
From nothing to Prometheus : one year after
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
Infrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using PrometheusInfrastructure & System Monitoring using Prometheus
Infrastructure & System Monitoring using Prometheus
 
0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a game
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
CEPH中的QOS技术
CEPH中的QOS技术CEPH中的QOS技术
CEPH中的QOS技术
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Skydive 5/07/2016
Skydive 5/07/2016Skydive 5/07/2016
Skydive 5/07/2016
 
202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP
 
Lab
LabLab
Lab
 
Docker Monitoring Webinar
Docker Monitoring  WebinarDocker Monitoring  Webinar
Docker Monitoring Webinar
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Build reliable, traceable, distributed systems with ZeroMQ

  • 1. Build reliable, traceable, distributed systems with ZeroMQ PYCON2012 @jpetazzo @dot_cloud
  • 2. Outline ● Who we are ● Quick tour of ZeroRPC features ● Implementation overview
  • 3. Introduction: why? ● We are running a PAAS: we deploy, monitor, and scale your apps (in the Cloud!) ● Many moving parts ● ... On a large distributed cluster
  • 4. API endpoint Users (auth) CLI Formation (analyzes stack) Uploader (code store) Containers (intances) Deployments (services) Cluster Node Cluster Node Cluster Node Cluster Node Host Info VHosts (HTTP) NATS (TCP/UDP) Load Balancer Load Balancer Logger Metrics Dashboard Internal tools dotCloud architecture (simplified) — components, servers, things receiving data from everything else, me
  • 5. Our requirements (easy) ● We want to be able to expose arbitrary code, with minimal modification (if any) If we can do import foo; foo.bar(42), we want to be able to do foo=RemoteService(...) ; foo.bar(42) ● We want a self-documented system We want to see methods, signatures, docstrings, without opening the code of the remote service, or relying on (always out-dated) documentation
  • 6. Our requirements (harder) ● We want to propagate exceptions properly ● We want to be language-agnostic ● We want to be brokerless, highly available, fast, and support fan-in/fan-out topologies (Not necessarily everything at the same time!) ● We want to trace & profile nested calls Which call initiated the subcall which raised SomeException? Which subcall of this complex call causes it to take forever?
  • 7. Why not {x} ? ● x=HTTP o too much overhead for some use-cases (logs and metrics) o continuous stream of updates requires extra work (chunked encoding, websockets...) o asynchronous notification requires extra work (long polling, websockets...) o fan-out topology requires extra work (implementing some kind of message queue) ● x=AMQP (or similar) o too much overhead for some use-cases
  • 8. What we came up with ZeroRPC! ● Based on ZeroMQ and MessagePack ● Supports everything we needed! ● Multiple implementations o Internal "reference" implementation in Python o Public "alternative" implementation with gevents o Internal Node.js implementation (so-so)
  • 9. Example: unmodified code Expose the "urllib" module over RPC: $ zerorpc-client --server --bind tcp://0:1234 urllib Yup. That's it. There is now something listening on TCP port 1234, and exposing the Python "urllib" module.
  • 10. Example: calling code From the command line (for testing): $ zerorpc-client tcp://0:1234 quote "hello pycon" "hello%20pycon" From Python code: >>> import zerorpc >>> remote_urllib = zerorpc.Client( ) >>> remote_urllib.connect('tcp://0:1234') >>> remote_urllib.quote('hello pycon') 'hello%20pycon'
  • 11. Example: introspection We can list methods: $ zerorpc-client tcp://localhost:1234 | grep ^q quote quote('abc def') -> 'abc%20def' quote_plus Quote the query fragment of a URL; replacing ' ' with '+' We can see signatures and docstrings: $ zerorpc-client tcp://localhost:1234 quote_plus - ? quote_plus(s, safe='') Quote the query fragment of a URL; replacing ' ' with '+'
  • 12. Example: exceptions $ zerorpc-client tcp://localhost:1234 quote_plus Traceback (most recent call last): File "/home/jpetazzo/.virtualenvs/dotcloud_develop/bin/zerorpc-client", line 131, in <module> main() File "/home/jpetazzo/.virtualenvs/dotcloud_develop/bin/zerorpc-client", line 127, in main pprint(client(args.command,*parameters)) File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 362, in __call__ return self.recv() File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 243, in recv ret = self.handler(headers, method, *args) File "/home/jpetazzo/Work/DOTCLOUD/dotcloud/zerorpc/zerorpc.py",line 323, in handle_result raise eTypeError: quote( ) takes at least 1 argument (0 given)
  • 13. Example: load balancing Start a load balancing hub: $ cat foo.yml in: "tcp://*:1111" out: "tcp://*:2222" type: queue $ zerohub.py foo.yml Start (at least) one worker: $ zerorpc-client --server tcp://localhost:2222 urllib Now connect to the "in" side of the hub: $ zerorpc-client tcp://localhost:1111
  • 14. Example: high availability Start a local HAProxy in TCP mode, dispatching requests to 2 or more remote services or hubs: $ cat haproxy.cfg listen zerorpc 0.0.0.0:1111 mode tcp server backend_a localhost:2222 check server backend_b localhost:3333 check $ haproxy -f haproxy.cfg Start (at least) one backend:$ zerorpc-client --server --bind tcp://0:2222 urllib Now connect to HAProxy:$ zerorpc-client tcp://localhost:1111
  • 15. Non-Example: PUB/SUB (not in public repo—yet) ● Broadcast a message to a group of nodes o But if a node leaves and rejoins, he'll lose messages ● Send a continuous stream of information o But if a speaker or listener leaves and rejoins... You generally don't want to do this! Better pattern: ZeroRPC streaming with gevents
  • 16. Example: streaming ● Server code returns an list iterator ● Client code gets an list iterator ● Small messages, high latency? No problem! o Server code will pre-push elements o Client code will notify server if pipeline runs low ● Huge messages? No problem! o Big data sets can be nicely chunked o They don't have to fit entirely in memory o Don't worry about timeouts anymore ● Also supports long polling
  • 17. Example: tracing (not in public repo—yet) $ dotcloud --trace alias add sushiblog.web www.deliciousrawfish.com TraceID: 48aca4f4-75d5-40f2-b5bd-73c40ca40980Ok. Now please add the following DNS record: www.deliciousrawfish.com. IN CNAME gateway.dotcloud.com. $ dotcloud-tracedump 48aca4f4-75d5-40f2-b5bd-73c40ca40980[2012-03-0723:56:17.759738] uwsgi@api --- run_command ---> api_00@zeroworkers(lag: 1ms | exec: 98ms) [2012-03-07 23:56:17.770432] api_00@zeroworkers --- track ---> mixpanel_00@zeroworkers (lag: 1ms | exec: 70ms) [2012-03-07 23:56:17.771264] api_00@zeroworkers --- km_track ---> mixpanel_01@zeroworkers (lag: 1ms | exec: 71ms) [2012-03-07 23:56:17.771994] api_00@zeroworkers--- km_track ---> mixpanel_02@zeroworkers (lag: 1ms | exec: 71ms) [2012-03-07 23:56:17.773041] api_00@zeroworkers--- record_event ---> users-events@users (lag: 0ms | exec: 0ms) [2012-03-07 23:56:17.774972] api_00@zeroworkers --- info (pending) ---> formation-in [Not Received] [2012-03-07 23:56:17.783590] api_00@zeroworkers --- info (pending) ---> formation-in [Not Received] [2012-03-07 23:56:17.830107] api_00@zeroworkers --- add_alias ---> deployments_04@deployments (lag: 0ms | exec: 27ms) [2012-03-07 23:56:17.831453] deployments_04@deployments --- exists_frontend ---> vhosts@vhosts (lag: 0ms | exec: 4ms) [2012-03-07 23:56:17.836288] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms) [2012-03-07 23:56:17.837370] deployments_04@deployments --- exists ---> vhosts@vhosts (lag: 0ms | exec: 1ms) [2012-03-07 23:56:17.838733] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms) [2012-03-07 23:56:17.840068] deployments_04@deployments --- add_frontend ---> vhosts@vhosts (lag: 0ms | exec: 15ms) [2012-03-07 23:56:17.856166] vhosts@vhosts --- OK ---> deployments_04@deployments (lag: 0ms | exec: 0ms) [2012-03-07 23:56:17.857647] deployments_04@deployments --- OK ---> api_00@zeroworkers(lag: 0ms | exec: 0ms) [2012-03-07 23:56:17.859824] api_00@zeroworkers --- OK ---> uwsgi@api (lag: 0ms | exec: 0ms)
  • 18. Implementation details This will be useful if... ● You think you might want to use ZeroRPC ● You think you might want to hack ZeroRPC ● You want to reimplement something similar ● You just happen to love distributed systems
  • 19. ØMQ ● Sockets on steroidshttp://zguide.zeromq.org/page:all ● Handles (re)connections for us ● Works over regular TCP ● Also has superfast ipc:// and inproc:// ● Different patterns: o REQ/REP (basic, synchronous RPC call + response) o PUB/SUB (shout and listen to streams of events) o PUSH/PULL (load balance or collect messages) o DEALER/ROUTER (REQ/REP with routing)
  • 20. Serialization: MessagePack In our tests, msgpack is more efficient than JSON, BSON, YAML: ● 20-50x faster ● serialized output is 2x smaller or better $ pip install msgpack-python >>> import msgpack >>> bytes = msgpack.dumps(data)
  • 21. Wire format Request: (headers, method_name, args) ● headers dict o no mandatory header o carries the protocol version number o used for tracing in our in-house version ● args o list of arguments o no named parameters Response: (headers, ERR|OK|STREAM, value)
  • 22. Timeouts ● ØMQ does not detect disconnections (or rather, it works hard to hide them) ● You can't know when the remote is gone ● Original implementation: 30s timeout ● Published implementation: heartbeat
  • 23. Introspection ● Expose a few special calls: o _zerorpc_list to list calls o _zerorpc_name to know who you're talking to o _zerorpc_ping (redundant with the previous one) o _zerorpc_help to retrieve the docstring of a call o _zerorpc_args to retrieve the argspec of a call o _zerorpc_inspect to retrieve everything at once ● Introspection + service discovery = WIN
  • 24. Naming ● Published implementation does not include any kind of naming/discovery ● In-house version uses a flat YAML file, mapping service names to ØMQ addresses and socket types ● In progress: use DNS records o SRV for host+port o TXT for ØMQ socket type (not sure about this!) ● In progress: registration of services o Majordomo protocol
  • 25. Security: there is none ● No security at all in ØMQ o assumes that you are on a private, internal network ● If you need to run "in the wild", use SSL: o bind ØMQ socket on localhost o run stunnel (with client cert verification) ● In progress: authentication layer ● dotCloud API is actually ZeroRPC, exposed through a HTTP/ZeroRPC gateway ● In progress: standardization of this gateway
  • 26. Tracing (not published yet) ● Initial implementation during a hack day o bonus: displays live latency and request rates, using http://projects.nuttnet.net/hummingbird/ o bonus: displays graphical call flow, using http://raphaeljs.com/ o bonus: send exceptions to airbrake/sentry ● Refactoring in progress, to "untie" it from the dotCloud infrastructure and Open Source it How it works: all calls and responses are logged to a central place, along with a trace_id unique to each sequence of calls.
  • 27. Tracing: trace_id ● Each call has a trace_id ● The trace_id is propagated to subcalls ● The trace_id is bound to a local context (think thread local storage) ● When making a call: o if there is a local trace_id, use it o if there is none ("root call"), generate one (GUID) ● trace_id is passed in all calls and responses Note: this is not (yet) in the github repository
  • 28. Tracing: trace collection ● If a message (sent or received) has a trace_id, we send out the following things: o trace_id o call name (or, for return values, OK|ERR+exception) o current process name and hostname o timestamp Internal details: the collection is built on top of the standard logging module.
  • 29. Tracing: trace storage ● Traces are sent to a Redis key/value store o each trace_id is associated with a list of traces o we keep some per-service counters o Redis persistence is disabled o entries are given a TTL so they expire automatically o entries were initially JSON (for easy debugging) o ... then "compressed" with msgpack to save space o approximately 16 GB of traces per day Internal details: the logging handler does not talk directly to Redis; it sends traces to a collector (which itself talks to Redis).
  • 30. The problem with being synchronous ● Original implementation was synchronous ● Long-running calls blocked the server ● Workaround: multiple workers and a hub ● Wastes resources ● Does not work well for very long calls o Deployment and provisioning of new cluster nodes o Deployment and scaling of user apps Note: this is not specific to ZeroRPC
  • 31. First shot at asynchronicity ● Send asynchronous events & setup callbacks ● "Please do foo(42) and send the result to this other place once you're done" ● We tried this. We failed. o distributed spaghetti code o trees falling in the forest with no one to hear them ● Might have worked better if we had... o better support in the library o better naming system o something to make sure that we don't lose calls
  • 32. Gevent to the rescue! ● Write synchronous code (a.k.a. don't rewrite your services) ● Uses coroutines to achieve concurrency ● No fork, no threads, no problems ● Monkey patch of the standard library (to replace blocking calls with async versions) ● Achieve "unlimited" concurrency server-side The version published on github uses gevent.
  • 33. Show me the code! https://github.com/dotcloud/zerorpc-python $ pip install git+git://github.com/dotcloud/zerorpc-python.git Has: zerorpc module, zerorpc-client helper, exception propagation, gevent integration Doesn't have: tracing, naming, helpers for PUB/SUB & PUSH/PULL, authentication