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

Solid Ground

Solid Ground

Empex, 2017

Saša Jurić

May 20, 2017
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. Solid ground
    @sasajuric
    aircloak.com

    View Slide

  2. pattern matching
    OTP metaprogramming
    mix
    Distillery
    the pipe operator
    Cowboy
    Plug
    Phoenix
    Ecto
    functional programming
    community
    GenStage
    Credo
    ExUnit
    Combine
    Poolboy
    Nerves

    View Slide

  3. View Slide

  4. LFE
    Erlang
    OTP
    BEAM Elixir
    Phoenix
    GenStage
    Ecto
    Plug
    magic source magic beneficiaries
    Cowboy Poolboy

    View Slide

  5. long-running system
    many tasks
    soft real-time
    finite time program
    all-or-nothing
    hard real-time

    View Slide

  6. scheduler scheduler scheduler scheduler
    BEAM
    CPU CPU CPU CPU

    View Slide

  7. frequent context switches

    View Slide

  8. t1
    t2
    t3
    t4
    t5
    10 s
    1 ms
    1 ms
    1 ms
    1 ms

    View Slide

  9. t1
    BEAM scheduler
    t2 t3 t4 t5
    t1

    View Slide

  10. t1
    cooperative scheduler
    t2 t3 t4 t5

    View Slide

  11. thread 1 thread n
    long running task long running task
    blocked
    cooperative scheduler

    View Slide

  12. thread 1 thread n
    long running task long running task
    BEAM scheduler

    not blocked :-)

    View Slide

  13. activities as runtime citizens

    View Slide

  14. send(pid, :please_stop)

    View Slide

  15. mref = Process.monitor(pid)
    send(pid, :please_stop)
    receive do
    {:DOWN, ^mref, :process, ^pid, _reason} ->
    :ok
    end

    View Slide

  16. mref = Process.monitor(pid)
    send(pid, :please_stop)
    receive do
    {:DOWN, ^mref, :process, ^pid, _reason} -> :ok
    after :timer.seconds(5) ->
    Process.exit(pid, :kill)
    receive do
    {:DOWN, ^mref, :process, ^pid, _reason} -> :ok
    end
    end

    View Slide

  17. task = Task.async(fn -> ... end)
    case Task.yield(task, :timer.seconds(5)) do
    {:ok, result} -> do_something(result)
    nil -> Task.shutdown(task, :brutal_kill)
    end

    View Slide

  18. shared-nothing concurrency

    View Slide

  19. Process
    heap
    resources

    View Slide

  20. process-owned “stuff” is released

    View Slide

  21. supervision tree

    View Slide

  22. system
    backend frontend
    chat history
    repo cache endpoint

    View Slide

  23. system
    backend
    chat history
    repo

    View Slide

  24. supervisor foundations
    frequent context switching
    activities as runtime citizens
    observable process termination
    stoppable processes
    shared-nothing concurrency

    View Slide

  25. syntax
    developer friendliness
    ecosystem

    View Slide

  26. runtime 

    guarantees
    syntax
    developer friendliness
    ecosystem

    View Slide

  27. Scales of Justice image taken from clipartfox.com
    How Erlang does scheduling http://jlouisramblings.blogspot.hr/2013/01/how-erlang-does-scheduling.html
    Erlang scheduler details https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/migration/
    2016/02/09/erlang-scheduler-details.html
    The BEAM book https://github.com/happi/theBeamBook
    BEAM wisdoms http://beam-wisdoms.clau.se/en/latest/
    Web based observer https://github.com/shinyscorpion/wobserver
    Recon http://ferd.github.io/recon/
    Erlang performance lab http://www.erlang.pl/

    View Slide