Modeling the real world with Elixir and OTP Aish Raj Dahal - - PowerPoint PPT Presentation

modeling the real world with elixir and otp
SMART_READER_LITE
LIVE PREVIEW

Modeling the real world with Elixir and OTP Aish Raj Dahal - - PowerPoint PPT Presentation

Modeling the real world with Elixir and OTP Aish Raj Dahal Concurrency, Events and Why are we the Real World here? Case study of an Elixir use Tour of the BEAM and OTP Demo time! Epilogue How did we get here ? Can


slide-1
SLIDE 1

Modeling the real world with Elixir and OTP

Aish Raj Dahal

slide-2
SLIDE 2

Why are we here?

  • Concurrency, Events and

the Real World

  • Case study of an Elixir

use

  • Tour of the BEAM and OTP
  • Demo time!
slide-3
SLIDE 3

How did we get here ?

Epilogue

slide-4
SLIDE 4
slide-5
SLIDE 5

“Can programming be liberated from the von Neumann style” ?

slide-6
SLIDE 6

Elixir is a programming language that leverages the power of Erlang VM (BEAM)

slide-7
SLIDE 7

With a simple syntax and a supportive community the language has seen tremendous growth

slide-8
SLIDE 8

A lot* of PagerDuty is powered by Elixir

slide-9
SLIDE 9

It has always not been this way.

slide-10
SLIDE 10

At PagerDuty it started as a language of choice for Rails- native way to talk to Kafka

slide-11
SLIDE 11

Why ?

slide-12
SLIDE 12

It was high value

slide-13
SLIDE 13

It was easy to redo it in a different language

slide-14
SLIDE 14

How was it ?

slide-15
SLIDE 15

It was not all rainbows and unicorns

slide-16
SLIDE 16

The application needed some tuning

slide-17
SLIDE 17

But language never got in the way

slide-18
SLIDE 18

Since then...

slide-19
SLIDE 19

A cambrian explosion in Elixir based services

slide-20
SLIDE 20

A good number of critical backend applications are written in Elixir

slide-21
SLIDE 21

All with the niceness of being built for the Real- World ™

slide-22
SLIDE 22

The Real World

Chapter I

slide-23
SLIDE 23

What is the Real World™?

slide-24
SLIDE 24

Are we talking about the universe ?

slide-25
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
SLIDE 26

The Real World ™ is the world we live in

slide-27
SLIDE 27

You must care about it because….

slide-28
SLIDE 28

When was the last time you programmed a non- multi-core computer ?

slide-29
SLIDE 29

Computer science is no more about computers than astronomy is about telescopes.

Edsger Dijkstra

slide-30
SLIDE 30

Software you write probably models a real world situation

slide-31
SLIDE 31

Software you write probably deals with events

slide-32
SLIDE 32

Mental model of the real world:

slide-33
SLIDE 33

It is inherently concurrent

slide-34
SLIDE 34

It is event-based

slide-35
SLIDE 35

Failures are unpredictable

slide-36
SLIDE 36

It tends to be “real time”

slide-37
SLIDE 37

Software you write for the Real World ™ should deal with these situations.

slide-38
SLIDE 38

Which means...

slide-39
SLIDE 39

Your software should be concurrent.

slide-40
SLIDE 40

Your software should deal with events

slide-41
SLIDE 41
slide-42
SLIDE 42

Your software should be fault- tolerant.

slide-43
SLIDE 43

Your software should respond to the user-input within a reasonable* time.

slide-44
SLIDE 44

Erlang solved these problems around three decades ago

slide-45
SLIDE 45

But this talk is not really about the Erlang programming language

slide-46
SLIDE 46

A Whirlwind tour of Elixir, BEAM and OTP

Chapter II

slide-47
SLIDE 47

Key ideas in Elixir

slide-48
SLIDE 48

Isolated Processes

slide-49
SLIDE 49
slide-50
SLIDE 50

Pure Message Passing between processes

slide-51
SLIDE 51
slide-52
SLIDE 52

The ability to detect errors in remote processes

slide-53
SLIDE 53

A method for determining what error caused a process to crash

slide-54
SLIDE 54
slide-55
SLIDE 55

This means that Elixir is

  • Concurrent
slide-56
SLIDE 56

This means that Elixir is

  • Concurrent
  • Fault tolerant
slide-57
SLIDE 57

This means that Elixir is

  • Concurrent
  • Fault tolerant
  • Soft real time
slide-58
SLIDE 58

And built in support for things like hot code swap

slide-59
SLIDE 59

Detour: Open Telecom Platform (OTP)

slide-60
SLIDE 60

OTP is a set of libraries and tools that provides fundamental abstractions for BEAM languages

slide-61
SLIDE 61

Here are some nice building blocks that OTP provides

slide-62
SLIDE 62

GenServer: A generic server

slide-63
SLIDE 63
slide-64
SLIDE 64

Process Supervisors

slide-65
SLIDE 65
slide-66
SLIDE 66

Agents: State Wrappers

slide-67
SLIDE 67
slide-68
SLIDE 68

Sounds like what you will want for the Real World ™

slide-69
SLIDE 69

Demo time

Chapter III

slide-70
SLIDE 70

Boids

slide-71
SLIDE 71

The rules of flight

slide-72
SLIDE 72

Separation: Steer to avoid crowding local flockmates

slide-73
SLIDE 73

Rule I: Separation

slide-74
SLIDE 74

Alignment: Steer towards the average heading of local flockmates

slide-75
SLIDE 75

Rule II: Alignment

slide-76
SLIDE 76

Cohesion: Steer to move toward the average position (center of mass) of local flockmates

slide-77
SLIDE 77

Rule III: Cohesion

slide-78
SLIDE 78

Modeling this with Elixir/OTP

slide-79
SLIDE 79
slide-80
SLIDE 80

Modeling the events

slide-81
SLIDE 81

Move

slide-82
SLIDE 82

Render

slide-83
SLIDE 83

Dealing with failures

slide-84
SLIDE 84

Restart the boid

slide-85
SLIDE 85

Concurrency

slide-86
SLIDE 86

Keep your processes light and have many of them.

slide-87
SLIDE 87

Epilogue

slide-88
SLIDE 88

Make it work, then make it beautiful, then if you really, really have to, make it fast.

Joe Armstrong

slide-89
SLIDE 89
  • @aishrajdahal