SLIDE 1
Modeling the real world with Elixir and OTP
Aish Raj Dahal
SLIDE 2 Why are we here?
the Real World
use
- Tour of the BEAM and OTP
- Demo time!
SLIDE 3
How did we get here ?
Epilogue
SLIDE 4
SLIDE 5
“Can programming be liberated from the von Neumann style” ?
SLIDE 6
Elixir is a programming language that leverages the power of Erlang VM (BEAM)
SLIDE 7
With a simple syntax and a supportive community the language has seen tremendous growth
SLIDE 8
A lot* of PagerDuty is powered by Elixir
SLIDE 9
It has always not been this way.
SLIDE 10
At PagerDuty it started as a language of choice for Rails- native way to talk to Kafka
SLIDE 11
Why ?
SLIDE 12
It was high value
SLIDE 13
It was easy to redo it in a different language
SLIDE 14
How was it ?
SLIDE 15
It was not all rainbows and unicorns
SLIDE 16
The application needed some tuning
SLIDE 17
But language never got in the way
SLIDE 18
Since then...
SLIDE 19
A cambrian explosion in Elixir based services
SLIDE 20
A good number of critical backend applications are written in Elixir
SLIDE 21
All with the niceness of being built for the Real- World ™
SLIDE 22
The Real World
Chapter I
SLIDE 23
What is the Real World™?
SLIDE 24
Are we talking about the universe ?
SLIDE 25 In the beginning the universe was created. This has made a lot of people very angry and been widely regarded as a bad move.
Douglas Adams, The Hitchhiker’s guide to the Galaxy
SLIDE 26
The Real World ™ is the world we live in
SLIDE 27
You must care about it because….
SLIDE 28
When was the last time you programmed a non- multi-core computer ?
SLIDE 29
Computer science is no more about computers than astronomy is about telescopes.
Edsger Dijkstra
SLIDE 30
Software you write probably models a real world situation
SLIDE 31
Software you write probably deals with events
SLIDE 32
Mental model of the real world:
SLIDE 33
It is inherently concurrent
SLIDE 34
It is event-based
SLIDE 35
Failures are unpredictable
SLIDE 36
It tends to be “real time”
SLIDE 37
Software you write for the Real World ™ should deal with these situations.
SLIDE 38
Which means...
SLIDE 39
Your software should be concurrent.
SLIDE 40
Your software should deal with events
SLIDE 41
SLIDE 42
Your software should be fault- tolerant.
SLIDE 43
Your software should respond to the user-input within a reasonable* time.
SLIDE 44
Erlang solved these problems around three decades ago
SLIDE 45
But this talk is not really about the Erlang programming language
SLIDE 46
A Whirlwind tour of Elixir, BEAM and OTP
Chapter II
SLIDE 47
Key ideas in Elixir
SLIDE 48
Isolated Processes
SLIDE 49
SLIDE 50
Pure Message Passing between processes
SLIDE 51
SLIDE 52
The ability to detect errors in remote processes
SLIDE 53
A method for determining what error caused a process to crash
SLIDE 54
SLIDE 55 This means that Elixir is
SLIDE 56 This means that Elixir is
- Concurrent
- Fault tolerant
SLIDE 57 This means that Elixir is
- Concurrent
- Fault tolerant
- Soft real time
SLIDE 58
And built in support for things like hot code swap
SLIDE 59
Detour: Open Telecom Platform (OTP)
SLIDE 60
OTP is a set of libraries and tools that provides fundamental abstractions for BEAM languages
SLIDE 61
Here are some nice building blocks that OTP provides
SLIDE 62
GenServer: A generic server
SLIDE 63
SLIDE 64
Process Supervisors
SLIDE 65
SLIDE 66
Agents: State Wrappers
SLIDE 67
SLIDE 68
Sounds like what you will want for the Real World ™
SLIDE 69
Demo time
Chapter III
SLIDE 70
Boids
SLIDE 71
The rules of flight
SLIDE 72
Separation: Steer to avoid crowding local flockmates
SLIDE 73
Rule I: Separation
SLIDE 74
Alignment: Steer towards the average heading of local flockmates
SLIDE 75
Rule II: Alignment
SLIDE 76
Cohesion: Steer to move toward the average position (center of mass) of local flockmates
SLIDE 77
Rule III: Cohesion
SLIDE 78
Modeling this with Elixir/OTP
SLIDE 79
SLIDE 80
Modeling the events
SLIDE 81
Move
SLIDE 82
Render
SLIDE 83
Dealing with failures
SLIDE 84
Restart the boid
SLIDE 85
Concurrency
SLIDE 86
Keep your processes light and have many of them.
SLIDE 87
Epilogue
SLIDE 88
Make it work, then make it beautiful, then if you really, really have to, make it fast.
Joe Armstrong