Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Exploring Processes and OTP behaviours in Erlang

Exploring Processes and OTP behaviours in Erlang

Dive into Erlang processes and the most used OTP behaviours

Paolo D'Incau

October 17, 2015
Tweet

More Decks by Paolo D'Incau

Other Decks in Programming

Transcript

  1. Exploring Processes and OTP behaviours in 17 ottobre Erlang -

    Elixir meetup Bologna
  2. @pdincau

  3. Funzionale General purpose Dinamico Concorrente Garbage collected - 1 -

    Erlang Run-Time System Ideato da Ericsson per la necessità di Business reali
  4. Soluzione ai problemi odierni e futuri Programmare diversamente - 2

    - PERCHÈ USARLO?
  5. “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 -
  6. - 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?
  7. - 5 - Actor Model TASK = fun(message) http:/ /learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency

    LA REALTÀ
  8. - 6 - Green Threads e message passing - 6

    - - 6 - PROCESSI
  9. - 7 - UN ESEMPIO PRATICO?

  10. - 8 - P1 P2 P2 ! {increment, N} COUNTER

    SERVER
  11. - 9 - COUNTER CODICE

  12. P1 P2 P2 ! {self(), {increment, N}} - 10 -

    P1 ! {Pid2, Result} CHIAMATA SINCRONA
  13. - 11 - COUNTER MIGLIORATO

  14. P1 P2 m1 P3 P4 P5 m2 m3 m4 -

    12 - COUNTERS
  15. - xx - PROVIAMO!

  16. P1 P2 P3 P4 - 13 - CRASH!

  17. - 14 - PRIMITIVE DI ERLANG spawn link spawn_link monitor

  18. NON COSÌ - 15 -

  19. {'EXIT', From, Reason} crash! crash! crash! - 16 - CRASH!

    CRASH! CHRASH! P1 P2 P3 P4
  20. trap_exit - 17 -

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

    Elixir - 18 -
  22. Librerie con pattern comuni che ci consentono di sviluppare applicazioni:

    - xx - DISTRIBUITE e FAULT TOLERANT - 18 -
  23. - 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
  24. - 20 - GEN_SERVER

  25. - 21 - GEN_SERVER

  26. - 22 - State(S) x Event(E) -> Actions(A), State(S') Lobby

    Idle Disconnected Reconnected timeout Stop GEN_FSM
  27. Wander Pursue Act Eat Act Act Act Act Act Act

    - 23 - GEN_FSM
  28. - 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
  29. - 25 - SUPERVISOR Main Sup. GCM 2 GCM 1

    Il cuore della affidabilità di Erlang
  30. - 26 - SUPERVISOR Sup. Main Sup. Seq. Worker Stash

    Worker “OTP: Supervisors” Programming Elixir Dave Thomas
  31. - 27 - APPLICATION Raccoglie codice comune a una funzionalità

    start/stop Organizzazione dei file Gestione delle configurazioni Riutilizzabile
  32. - 28 - RELEASE Una "release" è un insieme di

    applicazioni Erlang deployate ed eseguite assieme rebar3 è un grande passo avanti Gestione configurazioni
  33. - 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
  34. Grazie