Anatomy of an Elixir Process
11/2016
by Mustafa Turan
Erlang/Elixir Meetup
Zendesk - Dublin
What’s an Elixir Process?
Elixir Process inside BEAM
Actor Communication
Summary
10 min
@mustafaturan
STATE
Mailbox
CALCULATION FUNCTIONS
(MSG LISTENERS)
@mustafaturan
Elixir/Erlang Process
An actor
Erlang Virtual MachineOS
Process (1)
Process (2)
Process (3)
….
Process (n)
Erlang VM
-- pid 109
-- pid 206
-- pid 3114
-- ...
STATE
Mailbox
CALCULATION FUNCTIONS
(MSG LISTENERS)
(pid 109)
@mustafaturan
Sends a message with no-
reply
Christmas sales up to %90,
come to our new store and
start shopping!
(GenServer.cast)
Company A girl
@mustafaturan
Actor Communication
Basic / one direction
Sends a message
how r u?
Responses to message
Good! How r u?
(GenServer.call)
Mustafa Gozde
@mustafaturan
Actor Communication
Basic / bi-directional
Sends a message
Mustafa Gozde
is unreachable!
Changed her number
or
Out of charge
or
Airplane mode
Mobile Operator
Phone number is not
available
(GenServer.call)
@mustafaturan
Actor Communication
No process
Sends a message
(GenServer.call)
Mustafa has a TTL of 1 minute! Also knows the message delivered
She did not replied in one minute!
What will Mustafa do?
Mustafa Gozde
Send another message?
Try to reach her from other
channels / call her?
Go crazzy ????
He will behave like how you code it!
@mustafaturan
Actor Communication
TTL / bi-directional
Sends a message#1
Mustafa
Sends a message#2
Mustafa’s Message Box(1)
---------------------------------------
Message #1 from Gozde
Gozde
Other girl
Mustafa’s Message Box(2)
---------------------------------------
Message #1 from Gozde(*)
Message #2 from Other Girl
Mustafa’s Message Box(3)
---------------------------------------
Message #2 from Other Girl
Mustafa’s Message Box(4)
---------------------------------------
*Processing not finished yet
@mustafaturan
Responses to
message #1
Responses to
message #2
Mustafa may change its state depending on
messages.
Actor dies?
What happens if the actor dies?
Sends message to its supervisor
- Down/Exit:
- Depending on strategy, supervisor decide what to do.
- Could handle its own crash by catching the ‘exit’ signal
QUESTIONS
THANKS

Anatomy of an elixir process and Actor Communication

  • 1.
    Anatomy of anElixir Process 11/2016 by Mustafa Turan Erlang/Elixir Meetup Zendesk - Dublin
  • 2.
    What’s an ElixirProcess? Elixir Process inside BEAM Actor Communication Summary 10 min @mustafaturan
  • 3.
  • 4.
    Erlang Virtual MachineOS Process(1) Process (2) Process (3) …. Process (n) Erlang VM -- pid 109 -- pid 206 -- pid 3114 -- ... STATE Mailbox CALCULATION FUNCTIONS (MSG LISTENERS) (pid 109) @mustafaturan
  • 5.
    Sends a messagewith no- reply Christmas sales up to %90, come to our new store and start shopping! (GenServer.cast) Company A girl @mustafaturan Actor Communication Basic / one direction
  • 6.
    Sends a message howr u? Responses to message Good! How r u? (GenServer.call) Mustafa Gozde @mustafaturan Actor Communication Basic / bi-directional
  • 7.
    Sends a message MustafaGozde is unreachable! Changed her number or Out of charge or Airplane mode Mobile Operator Phone number is not available (GenServer.call) @mustafaturan Actor Communication No process
  • 8.
    Sends a message (GenServer.call) Mustafahas a TTL of 1 minute! Also knows the message delivered She did not replied in one minute! What will Mustafa do? Mustafa Gozde Send another message? Try to reach her from other channels / call her? Go crazzy ???? He will behave like how you code it! @mustafaturan Actor Communication TTL / bi-directional
  • 9.
    Sends a message#1 Mustafa Sendsa message#2 Mustafa’s Message Box(1) --------------------------------------- Message #1 from Gozde Gozde Other girl Mustafa’s Message Box(2) --------------------------------------- Message #1 from Gozde(*) Message #2 from Other Girl Mustafa’s Message Box(3) --------------------------------------- Message #2 from Other Girl Mustafa’s Message Box(4) --------------------------------------- *Processing not finished yet @mustafaturan Responses to message #1 Responses to message #2 Mustafa may change its state depending on messages.
  • 10.
    Actor dies? What happensif the actor dies? Sends message to its supervisor - Down/Exit: - Depending on strategy, supervisor decide what to do. - Could handle its own crash by catching the ‘exit’ signal
  • 11.
  • 12.