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

Solid Ground

Solid Ground

ElixirDaze 2017

Video available at https://www.youtube.com/watch?v=5SbWapbXhKo

Saša Jurić

March 06, 2017
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. Solid ground
    @sasajuric
    aircloak.com

    View full-size slide

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

    View full-size slide

  3. scheduler scheduler scheduler scheduler
    BEAM
    CPU CPU CPU CPU

    View full-size slide

  4. frequent context switches

    View full-size slide

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

    View full-size slide

  6. t1 t2 t3 t4 t5 t1
    BEAM scheduler

    View full-size slide

  7. t2 t3 t4 t5
    t1
    cooperative scheduler

    View full-size slide

  8. thread 1 thread n

    long running task long running task
    blocked
    cooperative scheduler

    View full-size slide

  9. thread 1 thread n

    long running task long running task
    not blocked :-)
    BEAM scheduler

    View full-size slide

  10. activities as runtime citizens

    View full-size slide

  11. send(pid, :please_stop)

    View full-size slide

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

    View full-size slide

  13. 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 full-size slide

  14. 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 full-size slide

  15. shared-nothing concurrency

    View full-size slide

  16. Process
    heap
    resources

    View full-size slide

  17. process-owned “stuff” is released

    View full-size slide

  18. supervision tree

    View full-size slide

  19. system
    backend frontend
    chat history
    repo cache endpoint

    View full-size slide

  20. system
    backend
    chat history
    repo

    View full-size slide

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

    View full-size slide

  22. runtime 

    guarantees
    syntax
    developer friendliness
    ecosystem

    View full-size slide

  23. Image credit
    Scales of Justice

    View full-size slide