SlideShare a Scribd company logo
1 of 64
Download to read offline
ElixirPeeking into Elixir’s
Processes, OTP & Supervisors
21st March 2014
/benjamintanweihao /bentanweihao
benjamintanweihao@gmail.com
What will we learn today?
Elixir & Erlang
In less than 5 minutes
Elixir & Erlang
In less than 5 minutes
Processes 101
The Basic Concurrency
Primitive
What will we learn today?
Elixir & Erlang
In less than 5 minutes
OTP
Framework and much more
Processes 101
The Basic Concurrency
Primitive
What will we learn today?
Elixir & Erlang
In less than 5 minutes
OTP
Framework and much more
Supervisors
Fault Tolerance & Recovery
Processes 101
The Basic Concurrency
Primitive
What will we learn today?
Ohai, Elixir!
Elixir & ErlangIn less than 5 minutes
Ohai, Erlang!
Erlang is a general-purpose concurrent,
garbage-collected programming language and
runtime system. The sequential subset of
Erlang is a functional language, with eager
evaluation, single assignment, and dynamic
typing. It was designed by Ericsson to support
distributed, fault-tolerant, soft-real-time, non-
stop applications. It supports hot swapping, so
that code can be changed without stopping a
system.
Ohai, Erlang!
Erlang is a general-purpose concurrent,
garbage-collected programming language and
runtime system. The sequential subset of
Erlang is a functional language, with eager
evaluation, single assignment, and dynamic
typing. It was designed by Ericsson to support
distributed, fault-tolerant, soft-real-time, non-
stop applications. It supports hot swapping, so
that code can be changed without stopping a
system.
• Free lunch is over
Why Elixir ?
Why Elixir ?
• Free lunch is over
• Hyper-threading & Multicore
• Faster software means using all
cores!
• But … Concurrency -> Coordination
• Functional makes this easier
Design Goals of Elixir
1.Productivity
2.Extensibility
3.Compatibility
Productivity
Complete Elixir Application
Productivity
Includes Supervisor Chain
Productivity
Testing built-in
Extensibility
Macros & Meta-programming
Implementing unless using if
Extensibility
Macros & Meta-programming
Implementing unless using if
Compatibility
Elixir can call Erlang code,
without any conversion
cost at all.
Compatibility
Elixir can use Erlang libraries!
The Actor Concurrency Model
• Actor = Process
The Actor Concurrency Model
• Actor = Process
• A process performs a specific task
when it receives a message
The Actor Concurrency Model
• Actor = Process
• A process performs a specific task
when it receives a message
• In turn, the process can reply to the
sender
The Actor Concurrency Model
• Actor = Process
• A process performs a specific task
when it receives a message
• In turn, the process can reply to the
sender
• All messages go to a processes’
mailbox – Q of unprocessed messages
sent from other processes that are not
yet consumed
The Actor Concurrency Model
• Actor = Process
• A process performs a specific task
when it receives a message
• In turn, the process can reply to the
sender
• All messages go to a processes’
mailbox – Q of unprocessed messages
sent from other processes that are not
yet consumed Shared-nothing Async Message-passing
Processes 101The Basic Concurrency Primitive
Creating Processes & Sending Messages in Elixir
Creating a Process
Creating Processes & Sending Messages in Elixir
Module, Function, Arguments
Creating Processes & Sending Messages in Elixir
Process id
Creating Processes & Sending Messages in Elixir
Sending a Message to w1
Creating Processes & Sending Messages in Elixir
Process waits for a message …
Creating Processes & Sending Messages in Elixir
Pattern matches!
Creating Processes & Sending Messages in Elixir
Result is sent back to the
calling process (self)
Creating Processes & Sending Messages in Elixir
Returns immediately
Creating Processes & Sending Messages in Elixir
Get result from self
Creating Processes & Sending Messages in Elixir Demo
OTPFramework and much more
What is OTP?
• Comes with Elixir/Erlang
• Framework to build
applications that are fault-
tolerant, scalable,
distributed
• Databases + Profilers +
Debuggers
OTP Behaviours
• GenServer
• Supervisor
• Application
An Example GenServer
Implement the GenServer
Behaviour
An Example GenServer
Implement GenServer Callbacks
An Example GenServer
Callbacks are NOT called explicitly
An Example GenServer
OTP calls the callbacks.
An Example GenServer
Synchronous Call:
Caller waits for reply
An Example GenServer
Asynchronous Call:
Caller doesn’t wait
for reply
An Example GenServer Demo
SupervisorsFault Tolerance & Recovery
Supervisors for Fault Tolerance and Recovery
one_for_one restart strategy
Supervisors for Fault Tolerance and Recovery
rest_for_all restart strategy
Supervisors for Fault Tolerance and Recovery
rest_for_one restart strategy
An Example Supervisor
Implement the Supervisor
Behaviour
An Example Supervisor
Declaring the Supervision
tree. Both Supervisors and
Workers (e.g. GenServers)
can be supervised.
An Example Supervisor
An Example Supervisor
Declare the restart strategy
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
one_for_one
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
one_for_all
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
simple_one_for_one
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
one_for_one
Supervisor Demo
Supervisor A
Supervisor B Supervisor C
Supervisor D
Server
D
Server
B
Worker 1Worker 1Worker
one_for_one
simple_one_for_one
one_for_all
one_for_one
Elixir & Erlang
In less than 5 minutes
OTP
Framework and much more
Supervisors
Fault Tolerance & Recovery
Processes 101
The Basic Concurrency
Primitive
Resources
Work in Progress!
!
Sign up at:
http://www.exotpbook.com
Me.
Stickers!**Very Limited Quantity
Thanks!
/benjamintanweihao /bentanweihao
benjamintanweihao@gmail.com

More Related Content

What's hot

Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 

What's hot (20)

How Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the OlympicsHow Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the Olympics
 
Elixir Phoenix
Elixir PhoenixElixir Phoenix
Elixir Phoenix
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in Elixir
 
Learning Elixir as a Rubyist
Learning Elixir as a RubyistLearning Elixir as a Rubyist
Learning Elixir as a Rubyist
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
effective_r27
effective_r27effective_r27
effective_r27
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
 
Nice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 applicationNice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 application
 
DDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves ElixirDDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves Elixir
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
 
Async await...oh wait!
Async await...oh wait!Async await...oh wait!
Async await...oh wait!
 
Ansible, Idempotency, and Jenkins
Ansible, Idempotency, and JenkinsAnsible, Idempotency, and Jenkins
Ansible, Idempotency, and Jenkins
 
Elixir and elm
Elixir and elmElixir and elm
Elixir and elm
 
Use the @types, Luke
Use the @types, LukeUse the @types, Luke
Use the @types, Luke
 
Elixir intro
Elixir introElixir intro
Elixir intro
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
2021laravelconftwslides6
2021laravelconftwslides62021laravelconftwslides6
2021laravelconftwslides6
 
Debugging ansible modules
Debugging ansible modulesDebugging ansible modules
Debugging ansible modules
 

Viewers also liked

Bottleneck in Elixir Application - Alexey Osipenko
 Bottleneck in Elixir Application - Alexey Osipenko  Bottleneck in Elixir Application - Alexey Osipenko
Bottleneck in Elixir Application - Alexey Osipenko
Elixir Club
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Elixir Club
 

Viewers also liked (20)

Build Your Own Real-Time Web Service with Elixir Phoenix
Build Your Own Real-Time Web Service with Elixir PhoenixBuild Your Own Real-Time Web Service with Elixir Phoenix
Build Your Own Real-Time Web Service with Elixir Phoenix
 
Bottleneck in Elixir Application - Alexey Osipenko
 Bottleneck in Elixir Application - Alexey Osipenko  Bottleneck in Elixir Application - Alexey Osipenko
Bottleneck in Elixir Application - Alexey Osipenko
 
Elixir basics-2
Elixir basics-2Elixir basics-2
Elixir basics-2
 
Elixir & Phoenix 推坑
Elixir & Phoenix 推坑Elixir & Phoenix 推坑
Elixir & Phoenix 推坑
 
Hello elixir (and otp)
Hello elixir (and otp)Hello elixir (and otp)
Hello elixir (and otp)
 
Elixir - Easy fun for busy developers @ Devoxx 2016
Elixir - Easy fun for busy developers @ Devoxx 2016Elixir - Easy fun for busy developers @ Devoxx 2016
Elixir - Easy fun for busy developers @ Devoxx 2016
 
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakBrief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
 
Flow-based programming with Elixir
Flow-based programming with ElixirFlow-based programming with Elixir
Flow-based programming with Elixir
 
Distributed system in Elixir
Distributed system in ElixirDistributed system in Elixir
Distributed system in Elixir
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
 
Elixir and Dialyzer, Types and Typespecs, using and understanding them
Elixir and Dialyzer, Types and Typespecs, using and understanding themElixir and Dialyzer, Types and Typespecs, using and understanding them
Elixir and Dialyzer, Types and Typespecs, using and understanding them
 
Building a Network IP Camera using Erlang
Building a Network IP Camera using ErlangBuilding a Network IP Camera using Erlang
Building a Network IP Camera using Erlang
 
The Magic Of Elixir
The Magic Of ElixirThe Magic Of Elixir
The Magic Of Elixir
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
ITB2016 - Mixing up the front end with ColdBox elixir
ITB2016 - Mixing up the front end with ColdBox elixirITB2016 - Mixing up the front end with ColdBox elixir
ITB2016 - Mixing up the front end with ColdBox elixir
 
Building Elixir App Release with Distillery and Docker
Building Elixir App Release with Distillery and DockerBuilding Elixir App Release with Distillery and Docker
Building Elixir App Release with Distillery and Docker
 
A Brief Introduction To Erlang
A Brief Introduction To ErlangA Brief Introduction To Erlang
A Brief Introduction To Erlang
 
Introduction to the Proteomics Bioinformatics Course 2016
Introduction to the Proteomics Bioinformatics Course 2016Introduction to the Proteomics Bioinformatics Course 2016
Introduction to the Proteomics Bioinformatics Course 2016
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for Rubyists
 
BioContainers on ELIXIR All Hands 2017
BioContainers on ELIXIR All Hands 2017BioContainers on ELIXIR All Hands 2017
BioContainers on ELIXIR All Hands 2017
 

Similar to Elixir – Peeking into Elixir's Processes, OTP and Supervisors

The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
l xf
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrency
yoavrubin
 

Similar to Elixir – Peeking into Elixir's Processes, OTP and Supervisors (20)

Elixir
ElixirElixir
Elixir
 
A sip of Elixir
A sip of ElixirA sip of Elixir
A sip of Elixir
 
OTP, Concurrency and Testing Strategies
OTP, Concurrency and Testing StrategiesOTP, Concurrency and Testing Strategies
OTP, Concurrency and Testing Strategies
 
Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"
 
Erlang, the big switch in social games
Erlang, the big switch in social gamesErlang, the big switch in social games
Erlang, the big switch in social games
 
Elixir otp-basics
Elixir otp-basicsElixir otp-basics
Elixir otp-basics
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammen
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
 
Phoenix for Rubyists
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for Rubyists
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
DevOps in the Real World
DevOps in the Real WorldDevOps in the Real World
DevOps in the Real World
 
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
 
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
From Ruby to Elixir
From Ruby to ElixirFrom Ruby to Elixir
From Ruby to Elixir
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrency
 
The dream BEAM - A former DevOps perspective
The dream BEAM - A former DevOps perspectiveThe dream BEAM - A former DevOps perspective
The dream BEAM - A former DevOps perspective
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
Module-1_Getting-Started_with_selenium_and_Java_basics.pdf
Module-1_Getting-Started_with_selenium_and_Java_basics.pdfModule-1_Getting-Started_with_selenium_and_Java_basics.pdf
Module-1_Getting-Started_with_selenium_and_Java_basics.pdf
 

Recently uploaded

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Elixir – Peeking into Elixir's Processes, OTP and Supervisors