SlideShare uma empresa Scribd logo
1 de 64
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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