anatomy of an elixir process and actor communication
TRANSCRIPT
![Page 1: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/1.jpg)
Anatomy of an Elixir Process11/2016by Mustafa Turan
Erlang/Elixir MeetupZendesk - Dublin
![Page 2: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/2.jpg)
What’s an Elixir Process?
Elixir Process inside BEAM
Actor Communication
Summary10 min
@mustafaturan
![Page 3: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/3.jpg)
STATE
Mailbox
CALCULATION FUNCTIONS(MSG LISTENERS)
@mustafaturan
Elixir/Erlang ProcessAn actor
![Page 4: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/4.jpg)
Erlang Virtual MachineOSProcess (1)
Process (2)
Process (3)
….
Process (n)
Erlang VM -- pid 109 -- pid 206 -- pid 3114 -- ...
STATE
Mailbox
CALCULATION FUNCTIONS(MSG LISTENERS)
(pid 109)
@mustafaturan
![Page 5: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/5.jpg)
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 CommunicationBasic / one direction
![Page 6: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/6.jpg)
Sends a messagehow r u?
Responses to messageGood! How r u?
(GenServer.call)
Mustafa Gozde
@mustafaturan
Actor CommunicationBasic / bi-directional
![Page 7: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/7.jpg)
Sends a message
Mustafa Gozdeis unreachable!
Changed her numberor
Out of chargeor
Airplane mode
Mobile Operator
Phone number is not available
(GenServer.call)
@mustafaturan
Actor CommunicationNo process
![Page 8: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/8.jpg)
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 GozdeSend another message?
Try to reach her from other channels / call her?
Go crazzy ????
He will behave like how you code it!@mustafaturan
Actor CommunicationTTL / bi-directional
![Page 9: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/9.jpg)
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.
![Page 10: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/10.jpg)
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
![Page 11: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/11.jpg)
QUESTIONS
![Page 12: Anatomy of an elixir process and Actor Communication](https://reader038.vdocuments.us/reader038/viewer/2022100801/58998dac1a28abb97c8b89af/html5/thumbnails/12.jpg)
THANKS