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

Elixir - Peeking into Processes, OTP & Supervisors

Elixir - Peeking into Processes, OTP & Supervisors

Talk I gave at Paypal Singapore on the 21st of March 2014 for Hackers and Painters.

Benjamin Tan Wei Hao

March 21, 2014
Tweet

More Decks by Benjamin Tan Wei Hao

Other Decks in Technology

Transcript

  1. Elixir & Erlang In less than 5 minutes Processes 101

    The Basic Concurrency Primitive What will we learn today?
  2. Elixir & Erlang In less than 5 minutes OTP Framework

    and much more Processes 101 The Basic Concurrency Primitive What will we learn today?
  3. Elixir & Erlang In less than 5 minutes OTP Framework

    and much more Supervisors Fault Tolerance & Recovery Processes 101 The Basic Concurrency Primitive What will we learn today?
  4. Ohai, Erlang! Erlang is a general-purpose concurrent, garbage-collected programming language

    and runtime system. The sequential subset of Erlang is a functional language, with eager evaluation, single assignment, and dynamic typing. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non- stop applications. It supports hot swapping, so that code can be changed without stopping a system.
  5. Ohai, Erlang! Erlang is a general-purpose concurrent, garbage-collected programming language

    and runtime system. The sequential subset of Erlang is a functional language, with eager evaluation, single assignment, and dynamic typing. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non- stop applications. It supports hot swapping, so that code can be changed without stopping a system.
  6. Why Elixir ? • Free lunch is over • Hyper-threading

    & Multicore • Faster software means using all cores! • But … Concurrency -> Coordination • Functional makes this easier
  7. The Actor Concurrency Model • Actor = Process • A

    process performs a specific task when it receives a message
  8. The Actor Concurrency Model • Actor = Process • A

    process performs a specific task when it receives a message • In turn, the process can reply to the sender
  9. The Actor Concurrency Model • Actor = Process • A

    process performs a specific task when it receives a message • In turn, the process can reply to the sender • All messages go to a processes’ mailbox – Q of unprocessed messages sent from other processes that are not yet consumed
  10. The Actor Concurrency Model • Actor = Process • A

    process performs a specific task when it receives a message • In turn, the process can reply to the sender • All messages go to a processes’ mailbox – Q of unprocessed messages sent from other processes that are not yet consumed Shared-nothing Async Message-passing
  11. What is OTP? • Comes with Elixir/Erlang • Framework to

    build applications that are fault- tolerant, scalable, distributed • Databases + Profilers + Debuggers
  12. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker
  13. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker one_for_one
  14. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker one_for_all
  15. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker simple_one_for_one
  16. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker one_for_one
  17. Supervisor Demo Supervisor A Supervisor B Supervisor C Supervisor D

    Server D Server B Worker 1 Worker 1 Worker one_for_one simple_one_for_one one_for_all one_for_one
  18. Elixir & Erlang In less than 5 minutes OTP Framework

    and much more Supervisors Fault Tolerance & Recovery Processes 101 The Basic Concurrency Primitive