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

Solid Ground

Solid Ground

Empex, 2017

Saša Jurić

May 20, 2017

More Decks by Saša Jurić

Other Decks in Programming


  1. Solid ground @sasajuric aircloak.com

  2. pattern matching OTP metaprogramming mix Distillery the pipe operator Cowboy

    Plug Phoenix Ecto functional programming community GenStage Credo ExUnit Combine Poolboy Nerves
  3. None
  4. LFE Erlang OTP BEAM Elixir Phoenix GenStage Ecto Plug magic

    source magic beneficiaries Cowboy Poolboy
  5. long-running system many tasks soft real-time finite time program all-or-nothing

    hard real-time
  6. scheduler scheduler scheduler scheduler BEAM CPU CPU CPU CPU

  7. frequent context switches

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

    ms 1 ms 1 ms
  9. t1 BEAM scheduler t2 t3 t4 t5 t1

  10. t1 cooperative scheduler t2 t3 t4 t5

  11. thread 1 thread n long running task long running task

    blocked cooperative scheduler …
  12. thread 1 thread n long running task long running task

    BEAM scheduler … not blocked :-)
  13. activities as runtime citizens

  14. send(pid, :please_stop)

  15. mref = Process.monitor(pid) send(pid, :please_stop) receive do {:DOWN, ^mref, :process,

    ^pid, _reason} -> :ok end
  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
  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
  18. shared-nothing concurrency

  19. Process heap resources

  20. process-owned “stuff” is released

  21. supervision tree

  22. system backend frontend chat history repo cache endpoint

  23. system backend chat history repo

  24. supervisor foundations frequent context switching activities as runtime citizens observable

    process termination stoppable processes shared-nothing concurrency
  25. syntax developer friendliness ecosystem

  26. runtime 
 guarantees syntax developer friendliness ecosystem

  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/