elixir processes
Post on 15-Apr-2017
162 Views
Preview:
TRANSCRIPT
PROCESSESELIXIR
OVERVIEW
TODAY’S AGENDA - PROCESSES▸ Why processes?▸ Conceptual framework▸ Basic usage▸ Next steps
ELIXIR PROCESSES
WHY PROCESSES?▸ Need more throughput▸ Run parallel computations▸ Concurrency causes problems▸ Control of failure
GIVEN A LIST OF CITIESAND A WEATHER APIRETRIEVE THE WEATHERFOR EACH CITY
User Story
PROCESSES OVERVIEW▸ Not a server process or thread
▸ A process in the Erlang VM (BEAM)
▸ Lightweight
▸ Utilizes all cores
ELIXIR PROCESSES
ELIXIR PROCESSES▸ send and receive messages▸ unique process id▸ message mailbox▸ execute asynchronously▸ isolated - no shared memory▸ hold state
ELIXIR PROCESSES
DRAW IT OUTPROCESS INTERACTIONS CAN BE DIFFICULT TO REASON ABOUT
A SIMPLE DIAGRAM CAN MAKE IT MUCH EASIER
GIVEN A LIST OF CITIESAND A WEATHER APIRETRIEVE THE WEATHERFOR EACH CITY
User Story
ELIXIR PROCESSES VS RUBY OBJECTS▸ #spawn #new
▸ process id instance
▸ #send/#receive .
▸ has state has state
▸ isolated memory shared memory
▸ asynchronous synchronous
live coding - spawn, send, receive
GIVEN A LIST OF CITIESAND A WEATHER APIRETRIEVE THE WEATHERFOR EACH CITY
User Story
ELIXIR PROCESSES
LINKING PROCESSES▸ Link processes with #spawn_link▸ Linking creates a parent-child relationship▸ Child exits by default cause the parent to exit▸ Exits can be “trapped” by a parent▸ Trapped exits let parents make a decision
live coding - linking processes and trapping exits
ELIXIR PROCESSES
WHAT HAVE WE GAINED?▸ More throughput▸ Easy, parallel computations▸ Avoidance of key concurrency problems▸ Failure control
ELIXIR PROCESSES
OTP IS NEXT▸ "Open Telecom Platform" is an
outdated name
▸ Let's just call it OTP
▸ A set of tools and abstractions to manage BEAM processes
‣ User story solution: https://github.com/adsteel/metex
‣ Live coding examples: https://gist.github.com/adsteel/3fb26673edc6892583c9fed588452d25
‣ Elixir Process Ping Pong - http://eddwardo.github.io/elixir/2015/10/22/elixir-pingpong-table/
‣ Trapping exits - http://www.akitaonrails.com/2015/11/22/observing-processes-in-elixir-the-little-elixir-otp-guidebook
‣ The Little Elixir and OTP Guidebook, by Benjamin Tan Wei Hao
‣ The Actor Model - https://www.youtube.com/watch?v=7erJ1DV_Tlo
Additional Resources
top related