ElixirDaze 2017
Video available at https://www.youtube.com/watch?v=5SbWapbXhKo
Solid ground@sasajuricaircloak.com
View Slide
long-running systemmany taskssoft real-timefinite time programall-or-nothinghard real-time
NIFs
scheduler scheduler scheduler schedulerBEAMCPU CPU CPU CPU
frequent context switches
t1t2t3t4t510 s1 ms1 ms1 ms1 ms
t1 t2 t3 t4 t5 t1BEAM scheduler
t2 t3 t4 t5t1cooperative scheduler
thread 1 thread n…long running task long running taskblockedcooperative scheduler
thread 1 thread n…long running task long running tasknot blocked :-)BEAM scheduler
activities as runtime citizens
send(pid, :please_stop)
mref = Process.monitor(pid)send(pid, :please_stop)receive do{:DOWN, ^mref, :process, ^pid, _reason} ->:okend
mref = Process.monitor(pid)send(pid, :please_stop)receive do{:DOWN, ^mref, :process, ^pid, _reason} ->:okafter :timer.seconds(5) ->Process.exit(pid, :kill)receive do{:DOWN, ^mref, :process, ^pid, _reason} ->:okendend
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
shared-nothing concurrency
Processheapresources
process-owned “stuff” is released
supervision tree
systembackend frontendchat historyrepo cache endpoint
systembackendchat historyrepo
supervisor foundationsfrequent context switchingactivities as runtime citizensobservable process terminationstoppable processesshared-nothing concurrency
runtime guaranteessyntaxdeveloper friendlinessecosystem
Image creditScales of Justice