Slide 1

Slide 1 text

@renanranelli It's about (run)time: Elixir Beyond the Hype 2018-09-22 Renan Ranelli

Slide 2

Slide 2 text

@renanranelli

Slide 3

Slide 3 text

Elixir Engineer @ Telnyx Chicago, IL Based in São Paulo @ Brasil Elixir since 2015 Organizer of Elixir SãoPaulo meetup Before Elixir, lot’s of Ruby, Python, C#, etc

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

(We're hiring !!!)

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

It's about (run)time: Elixir Beyond the Hype

Slide 9

Slide 9 text

DISCLAIMER

Slide 10

Slide 10 text

Language vs Platform

Slide 11

Slide 11 text

Definitions: 1. Erlang is a language 2. Erlang/OTP is a platform 3. Elixir is a language on top of the Erlang platform

Slide 12

Slide 12 text

Erlang/OTP

Slide 13

Slide 13 text

- Is a functional programming language - "Solves" concurrency for you - Is the "secret" behind Whatsapp - Half the world's telephony is built with it (citation needed) - Nine-nines of availability Things we hear about it:

Slide 14

Slide 14 text

The Erlang/OTP Runtime

Slide 15

Slide 15 text

- "Soft real time" - Preemptive scheduling (responsive, fair & low latency variance) - Vertically scalable - Distribution & Concurrency as a first class thing - Runtime guarantees for process execution (fault tolerance) - "High Performance" Characteristics of the Erlang VM

Slide 16

Slide 16 text

What about Elixir?

Slide 17

Slide 17 text

- Elixir compiles to the Erlang's bytecode - Created by a Brazilian! José Valim - The semantics of Elixir and Erlang are *absolutely the same*. There is no impedance mismatch - From the point of view of the platform, it makes absolutely no difference whether the source code is written in Erlang or Elixir (and this is HUGE) Elixir is just a small drop (pun intended)

Slide 18

Slide 18 text

"When designing the Erlang language and the Erlang VM, Joe,Mike and Robert did not aim to implement a functional programming language, they wanted a runtime where they could build distributed, fault-tolerant applications. It just happened that the foundation for writing such systems share many of the functional programming principles. And it reflects in both Erlang and Elixir. Therefore, the discussion becomes much more interesting when you ask about their end-goals and how functional programming helped them achieve them. The further we explore those goals,we realize how they tie in with immutability and the control of shared state, for example: ..." -- Valim, José Elixir Beyond Functional Programming

Slide 19

Slide 19 text

FAULT TOLERANCE

Slide 20

Slide 20 text

Fault-tolerance requires hardware redundancy Hardware redundancy requires Concurrency is a special case of distribution

Slide 21

Slide 21 text

So… why Elixir exists then?

Slide 22

Slide 22 text

- Erlang's syntax and ecosystem are Alien to modern software developers. - There are many barriers to its adoption: Lack of tooling, hard to read docs, mostly 0 data-polymorphism - Elixir brings the "21st century" to Erlang-land, via metaprogramming, tooling, excellent documentation and a very welcoming and vibrant community Why Elixir exists:

Slide 23

Slide 23 text

Erlang -> Hard Skills Elixir -> Soft Skills

Slide 24

Slide 24 text

Runtime logical organization

Slide 25

Slide 25 text

pid1 pid2 pid3 Erlang Node Scheduler 1 Scheduler Scheduler OS Thread Scheduler 2 OS Thread Scheduler 3 OS Thread pid1 pid1 OS PROCESS msg queue HEAP message

Slide 26

Slide 26 text

Preemptive Scheduling

Slide 27

Slide 27 text

Suppose we've got 6 tasks: T1 T2 T3 T4 T5

Slide 28

Slide 28 text

With *cooperative scheduling*: T1 T2 T3 T4 T5 T1 T2 T3 T4 T5 T1 T2 T3 T4 T5 1) Or 2) Or 3)

Slide 29

Slide 29 text

With *preemptive scheduling*: T1 T2 T3 T4 T5 1) Or 2) And so on and so on... T4 T5 T1 T2 T3 T4 T5 T4 T5 T5

Slide 30

Slide 30 text

Runtime guarantees: Process Monitoring

Slide 31

Slide 31 text

Process1 Pid0 (Monitors) Process Monitoring DEAD Msg queue GUARANTEED MSG DESCRIBING WHAT WENT ON THE PROCESS CAN HANDLE THIS MSG AND TAKE ACTION!!!

Slide 32

Slide 32 text

Supervision Trees

Slide 33

Slide 33 text

Supervision Trees DEAD

Slide 34

Slide 34 text

ACTIVITIES AS FIRST CLASS CITIZENS

Slide 35

Slide 35 text

- You can query & manipulate processes, the basic unit of execution in Erlang. - That means, you can handle it as *data* and manipulate, create, destroy, halt, garbage-collect them. - You can see what a process is doing now, what it has done before, who it talks to, who it monitors… pretty much *everything*. Activities as first-class citizens:

Slide 36

Slide 36 text

`:observer.start()`

Slide 37

Slide 37 text

Beyond the marketing

Slide 38

Slide 38 text

- Scalability, both horizontal and vertical - Using all cores for development - Elixir is crazy fast! (not really) - I don't need to care about GC at all! (not really) - Productivity!!! These are all *consequences* of the well defined fundamentals we just saw! The main selling points we see:

Slide 39

Slide 39 text

Because of that, the things we build with Elixir are, in general, very well engineered!

Slide 40

Slide 40 text

Example: Ecto's Connection Pool

Slide 41

Slide 41 text

Process Connection Pool 2) Set-up a monitor (!) Ecto Connection Pool Msg queue 5) Pool checks-in The connection ! 1) Check-out connection 4) message is sent telling the pool that the process died 2) Hand over connection 3) DIE

Slide 42

Slide 42 text

CONNECTION LEAKS ARE IMPOSSIBLE BY CONSTRUCTION (in this situation)

Slide 43

Slide 43 text

Actually… there is a lot more

Slide 44

Slide 44 text

- Clustering - Embedded data stores - Very powerful and lightweight tracing of pretty much anything - Logging and error reporting built in - Hot-code-deployments Other incredible things we did not cover

Slide 45

Slide 45 text

All of this is made possible because we've got good abstractions !

Slide 46

Slide 46 text

Wrapping up

Slide 47

Slide 47 text

- The greatest asset of Elixir is access to Erlang's Runtime & Platform. - Elixir is not magic. It won't solve all your problems in the blink of an eye, but it will give you a very powerful toolset and a vocabulary shared by *the whole community* on how to deal with failures & distribution. - Developer friendliness, metaprogramming and syntax are cool, but they are not the whole picture. - The "erlang-way" is present in all aspects of the platform and its community. This, IMHO, is something unattainable in other platform and is Elixir's trumph Wrapping up

Slide 48

Slide 48 text

Elixir is not (only) a hype.

Slide 49

Slide 49 text

Elixir is a well-engineered platform By engineers, for engineers.

Slide 50

Slide 50 text

Renan Ranelli milhouse@taming-chaos.com renan@telnyx.com Obrigado! Check us out! www.telnyx.com @renanranelli We're hiring!!