Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Life of an Erlang Process @robertoaloi

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Let’s talk about Erlang

Slide 5

Slide 5 text

I won’t talk about the Erlang syntax.

Slide 6

Slide 6 text

Syntax is Irrelevant Programming Language is Not When you’ll look at the syntax, it’ll be too late.

Slide 7

Slide 7 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS SCALABLE

Slide 8

Slide 8 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS FAULT-TOLERANT

Slide 9

Slide 9 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS HIGHLY AVAILABLE

Slide 10

Slide 10 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS MASSIVELY CONCURRENT

Slide 11

Slide 11 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS DISTRIBUTED

Slide 12

Slide 12 text

ERLANG HAS BEEN DESIGNED TO HELP YOU WRITING SYSTEMS SOFT REAL-TIME

Slide 13

Slide 13 text

The Erlang Rationale Users as Processes Scalable System Tons of Users Tons of Processes

Slide 14

Slide 14 text

Think Erlang Think Processes

Slide 15

Slide 15 text

Tons of them.

Slide 16

Slide 16 text

DEALING WITH TONS OF PROCESSES

Slide 17

Slide 17 text

Cheap to create Cheap to context switch OS processes out of discussion Use lightweight processes Built-in distribution to horizontally scale

Slide 18

Slide 18 text

SHARED MEMORY (or lack thereof)

Slide 19

Slide 19 text

Shared memory can leave the system in an inconsistent state after a restart or crash. Avoid it.

Slide 20

Slide 20 text

FAIL FAST

Slide 21

Slide 21 text

Faults are everywhere, you cannot prevent them. Report failure and die.

Slide 22

Slide 22 text

Processes are good. Can you show me one?

Slide 23

Slide 23 text

<0.42.0>

Slide 24

Slide 24 text

How are processes made? This is a little embarrassing, but… Ahem… I’m not sure I understand everything of it… I’ve heard rumours, still… Do you, do you mind if I ask you…

Slide 25

Slide 25 text

spawn(math, fact, [5]) math:fact(5) Pid2 Pid1

Slide 26

Slide 26 text

MESSAGE PASSING

Slide 27

Slide 27 text

Pid2 Pid1 Pid2 ! {self(), Msg} {Pid1, Msg} receive {From, start} -> … {From, stop} -> … end Send Receive

Slide 28

Slide 28 text

THE PROCESS SKELETON

Slide 29

Slide 29 text

start(Args) -> spawn(server, init, [Args]) init(Args) -> State = do_init(Args), loop(State). loop(State) ->
 receive
 {handle, Msg} -> 
 NewState = handle(Msg, State),
 loop(NewState);
 stop -> terminate(State)
 end. terminate(State) -> clean_up(State). Start Stop Initialize Terminate Loop

Slide 30

Slide 30 text

LINKS

Slide 31

Slide 31 text

PidB PidA link(PidB)

Slide 32

Slide 32 text

EXIT SIGNALS

Slide 33

Slide 33 text

PidA PidB {'EXIT', PidA, Reason} PidC {'EXIT', PidB, Reason}

Slide 34

Slide 34 text

TRAPPING EXIT SIGNALS

Slide 35

Slide 35 text

process_flag(trap_exit, true) PidA {'EXIT', PidA, Reason} PidC PidB

Slide 36

Slide 36 text

SUPERVISORS

Slide 37

Slide 37 text

PidA PidC PidB Supervisor Workers

Slide 38

Slide 38 text

erlang.org github.com/erlang/otp erlang-solutions.com www.learnyousomeerlang.org Erlang Programming Erlang and OTP in Action Official Home Page Sources Binary Packages, News, Events Best Online Tutorial Best book about basics Best book about OTP Where to Start

Slide 39

Slide 39 text

Questions? @robertoaloi Cover Image: “How computers are made” (Reddit - Ness4114)