Slide 1

Slide 1 text

Solid ground @sasajuric aircloak.com

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

scheduler scheduler scheduler scheduler BEAM CPU CPU CPU CPU

Slide 7

Slide 7 text

frequent context switches

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

t1 BEAM scheduler t2 t3 t4 t5 t1

Slide 10

Slide 10 text

t1 cooperative scheduler t2 t3 t4 t5

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

thread 1 thread n long running task long running task BEAM scheduler … not blocked :-)

Slide 13

Slide 13 text

activities as runtime citizens

Slide 14

Slide 14 text

send(pid, :please_stop)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

shared-nothing concurrency

Slide 19

Slide 19 text

Process heap resources

Slide 20

Slide 20 text

process-owned “stuff” is released

Slide 21

Slide 21 text

supervision tree

Slide 22

Slide 22 text

system backend frontend chat history repo cache endpoint

Slide 23

Slide 23 text

system backend chat history repo

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

syntax developer friendliness ecosystem

Slide 26

Slide 26 text

runtime 
 guarantees syntax developer friendliness ecosystem

Slide 27

Slide 27 text

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/