Upload
michel-perez
View
103
Download
1
Embed Size (px)
Citation preview
BY MICHEL PEREZELIXIR & PARALLEL PROGRAMMING
CONCURRENCY VS PARALLELISM
ELIXIR MECHANISMS
▸ PROCESS
▸ SPAWNING
▸ OTP
▸ GEN SERVER
▸ SUPERVISOR
▸ APPLICATION
PROCESSES
▸ Processes are the fundamental unit of concurrency in Elixir
▸ The Erlang VM supports up to 134 million of processes
▸ Lightweight processes
▸ Each actor is a process
▸ Each process performs a specific task
▸ Sends messages to communicate with the process
▸ The processes don’t share information
SPAWNING A PROCESS
PID
▸ Identifies a process in the EVM
▸ To send a message must point the pid
OTP
▸ The Erlang interpreter and compiler
▸ Erlang standard libraries
▸ Dialyzer, a static analysis tool
▸ Mnesia, a distributed database
▸ Erlang Term Storage (ETS), an in-memory database
▸ A debugger,
▸ An event tracer
▸ A release management tool
OTP BEHAVIOURS
▸ GenServer A behaviour module for implementing the server of a client-server relation.
▸ Supervisor A behaviour module for implementing supervision functionality
▸ Application A module for working with applications and defining application callbacks.
GEN SERVER - MODULE CALLS
▸ GenServer.start_link/3
▸ GenServer.call/3
▸ GenServer.cast/2
GEN SERVER - CALLBACKS
▸ init(args)
▸ handle_call(msg, {from, ref}, state}
▸ handle_cast(msg, state}
▸ handle_info(msg, state)
▸ terminate(reason, state)
▸ code_change(old_vsn, state, extra)
GENSERVER - INIT
▸ init(args)
▸ {:ok, state}
▸ {:ok, state, timeout}
▸ :ignore
▸ {:stop, reason}
GENSERVER - HANDLE CALL
▸ handle_call(msg, {from, ref},state)
▸ {:reply, reply, state}
▸ {:reply, reply, state, timeout}
▸ {:reply, reply, state, :hibernate}
▸ {:noreply, state}
▸ {:noreply, state, timeout}
▸ {:noreply, state, hibernate}
▸ {:stop, reason, reply, state}
▸ {:stop, reason, state}
GENSERVER - HANDLE CALL
▸ handle_cast(msg, state)
▸ {:noreply, state}
▸ {:noreply, state, timeout}
▸ {:noreply, state, :hibernate}
▸ {:stop, reason, state}
GENSERVER - HANDLE INFO - TERMINATE
▸ handle_info(msg, state)
▸ {:noreply, state}
▸ {:noreply, state, timeout}
▸ {:stop, reason, state}
▸ terminate(reason, state)
▸ :ok
GENSERVER - CODE CHANGE
▸ code_change(old_vsn, state, extra)
▸ {:ok, new_state}
▸ {:error, reason}
GENSERVER - EXAMPLE
SUPERVISOR
▸ Strategies
▸ :one_for_one
▸ :rest_for_one
▸ :one_for_all
▸ :simple_one_for_one
SUPERVISOR - EXAMPLE
APPLICATION
▸ Component implementing some specific functionality, that can be started and stopped as a unit, and which can be re-used in other systems
▸ Defines a supervision tree that must be started and stopped when the application starts and stops
▸ The start callback should return {:ok, pid}
APPLICATION - EXAMPLE
EXTREME
B1N1 N2
N3
N4
F1 N5
EXSTREME - CREATING A GRAPH
EXSTREME - RUNNING THE GRAPH
EXSTREME - NOTES
▸ https://github.com/mrkaspa/Exstreme
▸ Future
▸ Add Backpresure (GenStage)
▸ Supervising
▸ Remote nodes
THANKS!