Build custom protocols with Ranch and msgpack
Building protocols is fun!
Loïc Hoguin - @lhoguin
Erlang Cowboy and Nine Nines Founder
Essentials
Ranch
- Spin-off from Cowboy
- Transport and protocol agnostic acceptor pool
- Fully dynamic
- Well documented
- Production ready
- Tested with > 1 million Websocket connections
msgpack 1/2
- "It's like JSON. but fast and small."
- Binary serialization library
- Deserialization is streamable
- http://msgpack.org
msgpack 2/2
- Available for Ruby, Python, Perl, C/C++, Java, Scala, PHP, Lua, JavaScript, Node.js, Haskell, C#, Objective-C, Erlang, D, OCaml, Go, LabVIEW, Smalltalk
Guide to building a msgpack RPC service
- You most likely won't need async, sync is easier to pull off
- You most likely don't need connection pooling
- Follow the HTTP request/response model
- Send a request, expect a response, continue if successful
- Don't forget to close the connection when done
The future of Ranch
Custom connections supervisor
- Remove the need to monitor processes twice
- Reduce the overhead to a minimal
- No gen.erl, gen_server.erl
- No options to take care of, no restart strategy
- Bare minimum
Minimal supervisor
- Special process
- Traps exits
- Exit when parent exits
- Handle '$gen_call' messages
- Reply properly to which_children message
Results
- About 100LOCs for the supervisor
- Greatly simplified architecture of the project
- Much improved performance, especially with many connections
- Still OTP
Thanks!
- http://ninenines.eu
- https://github.com/extend/ranch
- #ninenines on Freenode
- @lhoguin on Twitter
Questions?