Why Elixir works magic?
(and Ruby does in limited amounts ;))
Hubert Łępicki
2015-10-17
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1843191/logo.png)
- Hubert Łępicki
- @hubertlepicki
- @amberbit
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815667/amberbit-logo.png)
I work with web apps
Web apps suck
Why?
JavaScript
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815734/trollface.png)
Server-side
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815737/servers.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815753/tomcat500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815756/rails500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815758/django500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815760/php500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816209/github.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815761/h500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815762/500-error.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815775/error.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815776/images__1_.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815777/500_internal_error.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815778/500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815779/jira_500.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815783/530_.gif)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815785/wildfire-500-internal-server-error.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815788/maxresdefault.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815790/server-error.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1815805/bomb.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816229/live_on_this_planet_futurama.gif)
Why making it work is hard?
- shared mutable data
- no built-in crash recovery mechanisms
- GC is hard
- threading is hard
- preempting is hard
- monitoring is hard
if only was there better VM
taking care of all those issues...
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816254/java.jpg)
Let's discuss memory allocation
Stack
- LIFO structure
- each function called adds stuff on top
- each function finished removes stuff from top
- VMs handle 1 stack per thread
Heap
- shared memory between all threads
- classes and types metadata
- dynamically allocated memory
Heap of problems
- global state needs synchronization
- slow access by different CPUs/cores
- single point of failure
- GC is a rocket science
Entirely different VM
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816279/Erlang_logo.png)
There is no shared heap
There is no problem synchronizing access to one
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816302/erts_mem.jpg)
Elixir
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816378/brewing.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816482/plug.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/116857/images/1816494/supervisor.png)
Writing supervised code
Hardware failure
OTP app cluster
- connect N nodes via (fast) web
- concurrency / message passing just works
- minimal changes to your code
- yay, you wrote distributed app by accident
- production-ready (remember dRB?)
- failover
- load balancing
- sleep well
Zero-downtime deployments
- elixir/erlang allows code hot-swapping
- your app is modular
- replace individual parts of system (applications)
- do not miss a single message
- do not loose a single HTTP request
Less infrastructure is more
Ruby on Rails
- [web] unicorn/puma + nginx/apache
- [worker] resque
- [scheduled tasks] cron + rake
- [websockets] faye/pusher
Elixir
[web] elixir
[worker] elixir
[scheduled tasks] elixir
[websockets] elixir
Application server
- bloat
+ speed
http://elixir-lang.org
Thank you!
@hubertlepicki
Why Elixir works magic?
By Hubert Łępicki
Why Elixir works magic?
- 1,659