SlideShare a Scribd company logo
{
Erlang and gen_fsm
@dieswaytoofast
(V.P. Ubiquiti Networks)
Finite State Machines - Why the fear?
The Business
Finite State Machines - Why the fear?
The Metrics
 Phone Calls per Second
The Metrics
 Phone Calls per Second
The Metrics
x 1000
 Simultaneous Phone Calls
The Metrics
 Simultaneous Phone Calls
The Metrics
x 10,000
 HTTP API requests
The Metrics
 HTTP API requests
The Metrics
x ∞
 Self-hosted (kinda)
 Voice Response
Call Handling
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Call Routing
Call Handling
dial_in
Check
Blacklist
get_endpoint conference Play Error
Hangupauto_attendant
dial_in_fml conference
init
Check node
Check
Blacklist
Cancelled Blacklisted Next Endpoint Collections Unknown
Move node
Auto Attendant FML Voicemail FaxConference
 Self-hosted (kinda)
Bet the farm moment
Finite State Machines - Why the fear?
ERLANG!!!
 Concurrency
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
 Code upgrade
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
 Concurrency
 Error encapsulation
 Fault detection
 Fault identification
 Code upgrade
 Stable Storage
The Big Six
From http://www.erlang.org/download/armstrong_thesis_2003.pdf
Erlang
Concurrency Hell
My Blue Heaven My Blue Heaven
Erlang
Concurrency Hell
My Blue Heaven
Deep Problems
My Blue Heaven
Deep Problems
 gen_server
Behaviours
 gen_server
 gen_tcp
Behaviours
 gen_server
 gen_tcp
 gen_event
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
 …
Behaviours
 gen_server
 gen_tcp
 gen_event
 gen_fsm
 …
Behaviours
 A System has States
Finite State Machines
asleepStart
out of
bed
Coffee!!
 A System has States
 States transition
Finite State Machines
asleepStart
out of
bed
Coffee!!
 A System has States
 States transition
 Transitions are Atomic
Finite State Machines
asleepStart
out of
bed
Coffee!!
NOTHING HERE
 A System has States
 States transition
 Transitions are Atomic
 Events at Entry and Exit
Finite State Machines
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
Finite State Machines - Why the fear?
asleepStart
out of
bed
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
HUH?
Finite State Machines - Why the fear?
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
asleepStart
out of
bed
Riiiiiiiiing Brush Teeth
Coffee!!
W
00t!
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Un-
Auth
Start
Token
Req.
Stop
Get
Request
Token
Get
Access
Token
Request
Token
Access
Token
 Everything is an FSM
Finite State Machines
 Everything is an FSM
Finite State Machines
COM
PLEXITY?
 Everything is an FSM
Finite State Machines
ENCAPSULATION!
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
 Voice Response
Finite State Machines
init
Setup Call
Get Caller
Name
Play Transfer
Message
Got Caller
Name
Dial
ENCAPSULATION!
Encapsulation
Concurrency Hell
My Blue Heaven
Deep Problems
My Blue Heaven
Deep Problems
 Call Routing
Finite State Machines
dial_in
Check
Blacklist
get_endpoint conference Play Error
Hangupauto_attendant
dial_in_fml conference
init
Check node
Check
Blacklist
Cancelled Blacklisted Next Endpoint Collections Unknown
Move node
Auto Attendant FML Voicemail FaxConference
 Templates are your friend
 So are BIG sheets of paper
 Think “Real World”
The Bottom Line
Finite State Machines - Why the fear?

More Related Content

PPT
Finite state machines
PPTX
Finite State Machines
PPT
Moore and mealy machines
PDF
NDC London 2014: Thinking Like an Erlanger
PPT
Introduction to State Machines
PPTX
Finite state machines
PPTX
Divide by N clock
PPT
Counters
Finite state machines
Finite State Machines
Moore and mealy machines
NDC London 2014: Thinking Like an Erlanger
Introduction to State Machines
Finite state machines
Divide by N clock
Counters

Viewers also liked (20)

PPT
Finite State Machine | Computer Science
PPT
Cldch8
PDF
OTP application (with gen server child) - simple example
PPT
Moore and Mealy machines
PDF
Introduction to Object Oriented Design
PDF
Sigma Knowledge Engineering Environment
PPT
Slide 3 musfique
PDF
Object Oriented Design And Programing
PPSX
Thinking and language
PPT
Unit 1(stld)
PPT
3.o o design -_____________lecture 3
PPT
Solving a “Transportation Planning” Problem through the Programming Language “C”
PPT
Mypresentation
DOCX
Structured systems analysis and design methodology
PPT
Problem solving using Computer
PPSX
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
PDF
Visualization of Hajime Yoshino’s Logical Jurisprudence. IRIS 2017
PDF
Machine Learning for Automated Reasoning: An Overview
PPT
Deterministic Finite Automata
PPT
Artificial Intelligence
Finite State Machine | Computer Science
Cldch8
OTP application (with gen server child) - simple example
Moore and Mealy machines
Introduction to Object Oriented Design
Sigma Knowledge Engineering Environment
Slide 3 musfique
Object Oriented Design And Programing
Thinking and language
Unit 1(stld)
3.o o design -_____________lecture 3
Solving a “Transportation Planning” Problem through the Programming Language “C”
Mypresentation
Structured systems analysis and design methodology
Problem solving using Computer
FINITE STATE MACHINE AND CHOMSKY HIERARCHY
Visualization of Hajime Yoshino’s Logical Jurisprudence. IRIS 2017
Machine Learning for Automated Reasoning: An Overview
Deterministic Finite Automata
Artificial Intelligence
Ad

Similar to Finite State Machines - Why the fear? (20)

PDF
Discover finite state machines with gen_statem in Erlang /Elixir
PPTX
"Final fsFighting Complex Application State Management with Finite-State Mach...
KEY
Ruby 1.9 Fibers
PDF
When RV Meets CEP (RV 2016 Tutorial)
KEY
Polyglot parallelism
PPT
A Practical Event Driven Model
PDF
Let it crash! The Erlang Approach to Building Reliable Services
PDF
Server Tips
PPTX
High Performance Relaying of C++11 Objects Across Processes and Logic-Labeled...
PDF
Parsing binaries and protocols with erlang
PPTX
Erlang - Because S**t Happens
PDF
Tips on High Performance Server Programming
PDF
Joe armstrong erlanga_languageforprogrammingreliablesystems
PDF
Advanced task management with Celery
KEY
Don’t block the event loop!
PDF
Using OTP and gen_server Effectively
ODP
An introduction to erlang
KEY
Concurrency in ruby
PDF
The State Machine Compiler
PDF
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Discover finite state machines with gen_statem in Erlang /Elixir
"Final fsFighting Complex Application State Management with Finite-State Mach...
Ruby 1.9 Fibers
When RV Meets CEP (RV 2016 Tutorial)
Polyglot parallelism
A Practical Event Driven Model
Let it crash! The Erlang Approach to Building Reliable Services
Server Tips
High Performance Relaying of C++11 Objects Across Processes and Logic-Labeled...
Parsing binaries and protocols with erlang
Erlang - Because S**t Happens
Tips on High Performance Server Programming
Joe armstrong erlanga_languageforprogrammingreliablesystems
Advanced task management with Celery
Don’t block the event loop!
Using OTP and gen_server Effectively
An introduction to erlang
Concurrency in ruby
The State Machine Compiler
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Ad

More from Mahesh Paolini-Subramanya (9)

PPTX
Drinking From The Firehose - The Erlang Way
PPTX
Syntax - Why so CareMad?
PPTX
PPTX
Active Queue Management (for Cloud Services)
PPTX
NoSQL learnings from the world of Telco
PPTX
Emerging Trends in Communications
PPTX
What I did on my Vacation (hint: Scuba & Erlang)
PPTX
Your business depends your customers - keeping them in the loop
PPTX
VoIP applications and the Cloud - Where gen_fsm really shines
Drinking From The Firehose - The Erlang Way
Syntax - Why so CareMad?
Active Queue Management (for Cloud Services)
NoSQL learnings from the world of Telco
Emerging Trends in Communications
What I did on my Vacation (hint: Scuba & Erlang)
Your business depends your customers - keeping them in the loop
VoIP applications and the Cloud - Where gen_fsm really shines

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mushroom cultivation and it's methods.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
August Patch Tuesday
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mushroom cultivation and it's methods.pdf
Hybrid model detection and classification of lung cancer
August Patch Tuesday
Web App vs Mobile App What Should You Build First.pdf
Hindi spoken digit analysis for native and non-native speakers
Encapsulation_ Review paper, used for researhc scholars
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
1 - Historical Antecedents, Social Consideration.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
A novel scalable deep ensemble learning framework for big data classification...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DP Operators-handbook-extract for the Mautical Institute
cloud_computing_Infrastucture_as_cloud_p
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
1. Introduction to Computer Programming.pptx
Zenith AI: Advanced Artificial Intelligence

Finite State Machines - Why the fear?

Editor's Notes

  • #3: So, I started a phone company. It was a great thing. Phones make people happy, right?
  • #4: Yeah. Kids. Don’t do this at home. Don’t start a phone company.
  • #5: But I did. Hosted phone services for SMBs. Vonage for small businesses. In the cloud. Awesome
  • #8: 3 orders of magnitude
  • #10: 4 orders of magnitude
  • #12: Infinity!
  • #13: Houston – we have a problem
  • #14: Consider the simplest case of handling a call
  • #15: It actually gets a lot more complex
  • #16: And eventually, a *lot* more complex
  • #17: To put it differently,It was a “bet the farm” moment
  • #18: And it basically involved a lot of beer
  • #19: And we rewrote the whole damn thing in Erlang. WhyErlang? Well, Fault Tolerance, basicallyAnd oh, I’m not putting Kirk up there. That’s too obvious.
  • #20: The Six Essential Characteristics of a Fault Tolerant System
  • #21: The Six Essential Characteristics of a Fault Tolerant System
  • #22: The Six Essential Characteristics of a Fault Tolerant System
  • #23: The Six Essential Characteristics of a Fault Tolerant System
  • #24: The Six Essential Characteristics of a Fault Tolerant System
  • #25: The Six Essential Characteristics of a Fault Tolerant System
  • #26: ‘Distributed’ problems mean you spend a huge chunk of your time dealing with theadminstrivia of distribution.With erlang you get that for free!
  • #27: Ok, not really true. You still have to deal with ‘deep problems’ (hard core parallelization issues, etc.)But you’d have to deal with that anyhow!
  • #28: Implement the server part of a client/server relationship
  • #29: Talk to tcp over sockets
  • #30: Event handling
  • #31: Finite state machines
  • #32: And a bunch more (gen_udp, gen_utp!, etc.)
  • #33: But, we’re talking about Finite State Machines
  • #34: Lets talk about FSMs
  • #42: Putting this into practice, here is some code
  • #43: A system has states
  • #44: When certain events show up
  • #45: You do something
  • #46: And transition to the next state
  • #47: Wait, WHUT? Where did the “events” come from?
  • #48: I’m glad you asked  more code
  • #49: And thusly an event is sent
  • #50: Voila, an ErlangFSM
  • #51: 2.0 is anightmare; Stick w/ 1.0
  • #52: A system has states
  • #53: Events and transitions
  • #54: The code
  • #55: The states
  • #57: When you receive an event
  • #58: try to do something
  • #59: If it works go to the next state
  • #61: If it fails, go to a differen state
  • #62: Thusly
  • #63: And now for the events
  • #68: But wait! What if you walk out partway?
  • #69: So, a wee bit triclyhere -
  • #70: We have a timeout
  • #71: And it tells you where to go after the timeout
  • #72: And, you’re done.
  • #73: Lets look at this as a ‘real world” thingy
  • #74: But, you say, BUT, what about the complexity of dealing with FSMs? They’re big! And unweildy!
  • #75: Nah. They aren’t. Not in Erlang
  • #76: Remember this? It was a PITA? Actually, a small part of a PITA?
  • #77: But each one is tightly encapsulated, and clean.It’s the Erlang Way
  • #78: But each one is tightly encapsulated, and clean.It’s the Erlang Way
  • #79: My fanciful slides are actually real. This actually happens.
  • #80: And it’s the same for everything else I showed. FSMs of FSMs.
  • #81: An FSM of FSMs of FSMsBuilding these out “correctly”, in real time, is (was!) trivial
  • #82: “Real World”  Business Rules can help. (VM,syncrhonziation)