Phoenix Framework for the realtime webPedro Medeiros
Summary
Summary
● Erlang model● Brief Elixir● Phoenix motivation● Phoenix Channels
Erlang
● Created in 1986● Solves a specific Hard problem at the time● Limited Resources● In Brief
○ Fault-Tolerance○ High Disponibility○ Concurrent Oriented
Switch
Switch
phones
Erlang
● Achievements○ No shared state concurrency focused○ Live code reloading○ Clustering through message passing (Actor
Model)○ High Availability 99.9999999 % (nine Nines)○ Used in GPRS, 3G and LTE networks worldwide
Erlang
Switch
Switch
phones
Server
Browser
App
IoT
Endpoints
2 Million connections on a single nodehttps://blog.whatsapp.com/196/1-million-is-so-2011?
Erlang
Fibonacci example:
Erlang
World Counter example:
Elixir
● Functional Programming language.● On top of Erlang VM● Immutable structures● Concurrent● Distributed● Fault Tolerant
Elixir
● Design Goals○ Extensibility○ Productivity○ Compatibility
Elixir
● Extensibility○ Ad hoc Polymorphism (data type)○ Strict and lazy enumeration APIs○ Macros for metaprogramming
● Macros
Elixir
● Macros
Elixir
Elixir
● Productivity○ Out of the box tools to startup a project○ Nice syntax for test and documentation○ Easy to distribute and to create libs
● Testing asserts
Elixir
Elixir
● Compatibility○ Compiles to ErlangVM○ Elixir runs Erlang code Erlang runs Elixir code○ Community grown
● Calling Erlang from elixir
● Calling Elixir from Erlang
Elixir
● Exchange Code between those two.
Elixir
Disclaimer
Elixir is not about a better syntax for the Erlang VM
2 Million connections on a single nodehttps://blog.whatsapp.com/196/1-million-is-so-2011?
Phoenix
● Started with Phoenix Channels○ Inspired by the whatsapp case○ Real time communication○ Beyond browsers (native apps and IoTs)
Phoenix
Easy Abstraction in javascript
Phoenix
Simple Backend code
Server
Server
Browser
Native
IoTs
Phoenix
PubSub
Phoenix
client server
Channels
socket.connect()
Distributed ErlangRedisPostgres?XMPP?
- Isolated- Concurrent
The road to 2 million connections
○ 40 core 128 gb Rack space machine○ Accomplish it with minor changes.
Phoenix
http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-connections
PhoenixThe road to 2 million connections
Phoenix Benchmarks
"There are three kinds of lies: lies, damned lies, and statistics."- Clarisse Linspector
Phoenix Benchmarks
$ wrk -t20 -c100 -d30s --timeout 2000https://github.com/mroth/phoenix-showdown
Library Throughput (req/s) Latency (m/s)
Plug (elixir) 198 328 0.63
Phoenix (elixir) 179 685 0.61
Gin (go) 176 156 0.65
Play (scala) 171 236 1.89
Express Cluster (node) 92 064 1.24
Martini (go) 32 077 3.35
Sinatra (ruby) 30 561 3.50
Rails (ruby) 11 903 8.50
Phoenix
client server
/index
/permissions
/settings
- Isolated- Concurent
Productivity
Short term productivity vsLong term productivity
Short term productivity
● Great documentation as first class citizen● Guides● Code generators (as a learning tool)
○ mix phx.gen.html○ mix phx.gen.json○ mix phx.gen.channel
Short term productivity
● HTML Form Builders● Great live code reloading● Assets build tools with ES6 as default● Pretty error pages● First Class concurrent test tools
Long term productivity
● OTP Applications○ Functional Programming○ Introspection○ Monitoring○ Fault Tolerant○ Supervisors○ Visibility of application state
Long term productivity
Wrapping up
Thanks ;)