Slide 1

Slide 1 text

Exploring Processes and OTP behaviours in 17 ottobre Erlang - Elixir meetup Bologna

Slide 2

Slide 2 text

@pdincau

Slide 3

Slide 3 text

Funzionale General purpose Dinamico Concorrente Garbage collected - 1 - Erlang Run-Time System Ideato da Ericsson per la necessità di Business reali

Slide 4

Slide 4 text

Soluzione ai problemi odierni e futuri Programmare diversamente - 2 - PERCHÈ USARLO?

Slide 5

Slide 5 text

“If we want to write programs that behave as other objects behave in the real world, then these programs will have a concurrent structure. Use a language that was designed for writing concurrent applications, and development becomes a lot easier. Erlang programs model how we think and interact.” Joe Armstrong Programming Erlang - 1st Edition - 3 -

Slide 6

Slide 6 text

- 4 - Moduli o Classi “It’s OO, but pretend it isn’t, please” Fred Hebert Joe Armstrong / Ralph Johnson infoq.com/interviews/johnson-armstrong-oop ferd.ca/an-open-letter-to-the-erlang-beginner-or-onlooker.html VENITE DAL MONDO OOP?

Slide 7

Slide 7 text

- 5 - Actor Model TASK = fun(message) http:/ /learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency LA REALTÀ

Slide 8

Slide 8 text

- 6 - Green Threads e message passing - 6 - - 6 - PROCESSI

Slide 9

Slide 9 text

- 7 - UN ESEMPIO PRATICO?

Slide 10

Slide 10 text

- 8 - P1 P2 P2 ! {increment, N} COUNTER SERVER

Slide 11

Slide 11 text

- 9 - COUNTER CODICE

Slide 12

Slide 12 text

P1 P2 P2 ! {self(), {increment, N}} - 10 - P1 ! {Pid2, Result} CHIAMATA SINCRONA

Slide 13

Slide 13 text

- 11 - COUNTER MIGLIORATO

Slide 14

Slide 14 text

P1 P2 m1 P3 P4 P5 m2 m3 m4 - 12 - COUNTERS

Slide 15

Slide 15 text

- xx - PROVIAMO!

Slide 16

Slide 16 text

P1 P2 P3 P4 - 13 - CRASH!

Slide 17

Slide 17 text

- 14 - PRIMITIVE DI ERLANG spawn link spawn_link monitor

Slide 18

Slide 18 text

NON COSÌ - 15 -

Slide 19

Slide 19 text

{'EXIT', From, Reason} crash! crash! crash! - 16 - CRASH! CRASH! CHRASH! P1 P2 P3 P4

Slide 20

Slide 20 text

trap_exit - 17 -

Slide 21

Slide 21 text

“…OTP, the 800-pound gorilla of process architecture” Dave Thomas Programming Elixir - 18 -

Slide 22

Slide 22 text

Librerie con pattern comuni che ci consentono di sviluppare applicazioni: - xx - DISTRIBUITE e FAULT TOLERANT - 18 -

Slide 23

Slide 23 text

- 19 - Modella il server di una relazione di tipo client-server Server Client Client Client Query Reply http:/ /www.erlang.org/doc/design_principles/gen_server_concepts.html GEN_SERVER

Slide 24

Slide 24 text

- 20 - GEN_SERVER

Slide 25

Slide 25 text

- 21 - GEN_SERVER

Slide 26

Slide 26 text

- 22 - State(S) x Event(E) -> Actions(A), State(S') Lobby Idle Disconnected Reconnected timeout Stop GEN_FSM

Slide 27

Slide 27 text

Wander Pursue Act Eat Act Act Act Act Act Act - 23 - GEN_FSM

Slide 28

Slide 28 text

- 24 - GEN_EVENT server event manager g(event) f(event) h(event) event “Profiling and Debugging Erlang Systems” Martin Kjellin, Roberto Aloi youtube.com/watch?v=4u6c2FNauYE

Slide 29

Slide 29 text

- 25 - SUPERVISOR Main Sup. GCM 2 GCM 1 Il cuore della affidabilità di Erlang

Slide 30

Slide 30 text

- 26 - SUPERVISOR Sup. Main Sup. Seq. Worker Stash Worker “OTP: Supervisors” Programming Elixir Dave Thomas

Slide 31

Slide 31 text

- 27 - APPLICATION Raccoglie codice comune a una funzionalità start/stop Organizzazione dei file Gestione delle configurazioni Riutilizzabile

Slide 32

Slide 32 text

- 28 - RELEASE Una "release" è un insieme di applicazioni Erlang deployate ed eseguite assieme rebar3 è un grande passo avanti Gestione configurazioni

Slide 33

Slide 33 text

- 29 - Erlang in production: "I wish I'd known that when I started" Bernard Duggan youtube.com/watch?v=G0eBDWigORY Thinking like an Erlanger Torben Hoffmann youtube.com/watch?v=_fgaPGLGZI0 RISORSE UTILI

Slide 34

Slide 34 text

Grazie