際際滷

際際滷Share a Scribd company logo
BY MICHEL PEREZ
ELIXIR & 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 speci鍖c task
 Sends messages to communicate with the process
 The processes dont share information
SPAWNING A PROCESS
PID
 Identi鍖es 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
de鍖ning 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 speci鍖c functionality, that
can be started and stopped as a unit, and which can be re-
used in other systems
 De鍖nes 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!

More Related Content

Elixir par

  • 1. BY MICHEL PEREZ ELIXIR & PARALLEL PROGRAMMING
  • 3. ELIXIR MECHANISMS PROCESS SPAWNING OTP GEN SERVER SUPERVISOR APPLICATION
  • 4. 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 speci鍖c task Sends messages to communicate with the process The processes dont share information
  • 6. PID Identi鍖es a process in the EVM To send a message must point the pid
  • 7. 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
  • 8. 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 de鍖ning application callbacks.
  • 9. GEN SERVER - MODULE CALLS GenServer.start_link/3 GenServer.call/3 GenServer.cast/2
  • 10. 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)
  • 11. GENSERVER - INIT init(args) {:ok, state} {:ok, state, timeout} :ignore {:stop, reason}
  • 12. 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}
  • 13. GENSERVER - HANDLE CALL handle_cast(msg, state) {:noreply, state} {:noreply, state, timeout} {:noreply, state, :hibernate} {:stop, reason, state}
  • 14. GENSERVER - HANDLE INFO - TERMINATE handle_info(msg, state) {:noreply, state} {:noreply, state, timeout} {:stop, reason, state} terminate(reason, state) :ok
  • 15. GENSERVER - CODE CHANGE code_change(old_vsn, state, extra) {:ok, new_state} {:error, reason}
  • 17. SUPERVISOR Strategies :one_for_one :rest_for_one :one_for_all :simple_one_for_one
  • 19. APPLICATION Component implementing some speci鍖c functionality, that can be started and stopped as a unit, and which can be re- used in other systems De鍖nes a supervision tree that must be started and stopped when the application starts and stops The start callback should return {:ok, pid}
  • 23. EXSTREME - RUNNING THE GRAPH
  • 24. EXSTREME - NOTES https://github.com/mrkaspa/Exstreme Future Add Backpresure (GenStage) Supervising Remote nodes