Created: 2022-06-07 Tue 22:11
Kotlin | Elixir | |
---|---|---|
Primary | Java | Erlang |
Others | Groovy, Scala | LFE, Alpaca |
VM | JVM | BEAM |
Figure 1: Erlang ecosystem
131 out of 132 bugs are transient bugs – Jim Gray in Why Do Computers Stop and What Can Be Done About It? (1985)
iex> pid = spawn(fn -> 1 + 2 end)
#PID<0.44.0>
iex> Process.alive?(pid)
false
iex> pid = spawn(fn ->
Process.sleep(:infinity)
end)
#PID<0.44.0>
iex> Process.alive?(pid)
true
iex> Process.exit(pid, :kill)
true
iex> x = 1
iex> Task.async(fn -> x = 3 end) |> Task.await
3
iex> x
1
send(
process_b,
{:hello, self()}
)
receive do
reply ->
IO.puts(reply)
end
receive do
{:hello, from} ->
send(from, "Hello there")
other ->
handle(other)
end
iex> pid = spawn(fn ->
Process.sleep(5_000)
raise "error"
end)
#PID<0.118.0>
iex> send(pid, :request)
:request
iex> receive do
response -> response
end
... blocks forever since process will die ...
iex> pid = spawn_link(fn ->
Process.sleep(5_000)
raise "error"
end)
#PID<0.118.0>
iex> send(pid, :request)
:request
iex> receive do
response -> response
end
... after 5 seconds when pid dies, so does iex ...
... crash report ...
... iex restarts ...
iex> pid = spawn(fn ->
Process.sleep(5_000)
raise "error"
end)
#PID<0.124.0>
iex> Process.monitor(pid)
#Reference<0.1858197913.2995257347.242321>
… after 5 seconds …
16:24:40.967 [error] Process #PID<0.124.0> raised an exception
** (RuntimeError) error
(stdlib 3.12) erl_eval.erl:678: :erl_eval.do_apply/6
iex> flush
{:DOWN, #Reference<0.1858197913.2995257347.242321>, :process, #PID<0.124.0>,
{%RuntimeError{message: "error"},
[{:erl_eval, :do_apply, 6, [file: 'erl_eval.erl', line: 678]}]}}
:ok
defmodule Ping do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end
def init(state) do
{:ok, state}
end
def handle_call(:ping, _from, state) do
{:reply, :pong, state}
end
end
iex> Ping.start_link(nil)
{:ok, #PID<0.232.0>}
iex> GenServer.call(Ping, :ping)
:pong
iex> GenServer.call(Ping, :wrong)
... crashes and worker is dead now ...
iex> Supervisor.start_link([Ping], strategy: :one_for_one)
{:ok, #PID<0.239.0>}
iex> GenServer.call(Ping, :wrong)
... crashes, but supervisor restarts the worker...
iex> GenServer.call(Ping, :ping)
:pong
At Facebook acquisition in 2014
Uptime: 99.9999999% over 20 years
Figure 2: AXD301 ATM switch
Switch Push Notification Infrastructure (NPNS)
In June 2019
… much more