Finite State Machines - Why the fear?

Preview:

DESCRIPTION

Finite State Machines are overlooked at best, ignored at worst, and virtually always dismissed. This is tragic since FSMs are not just about Door Locks (the most commonly used example). On the contrary, these FSMs are invaluable in clearly defining communication protocols – ranging from low-level web-services through complex telephony application to reliable interactions between loosely-coupled systems. Properly using them can significantly enhance the stability and reliability of your systems. Join me as I take you through a crash-course in FSMs, using erlang’s gen_fsm behavior as the background, and hopefully leaving you with a better appreciation of both FSM and erlang in the process.

Citation preview

{

Erlang and gen_fsm

@dieswaytoofast (V.P. Ubiquiti Networks)

The Business

The Metrics

Phone Calls per Second

The Metrics

Phone Calls per Second

The Metrics

Simultaneous Phone Calls

The Metrics

Simultaneous Phone Calls

The Metrics

HTTP API requests

The Metrics

HTTP API requests

The Metrics

Self-hosted (kinda)

Voice Response

Call Handling

Call Routing

Call Handling

Self-hosted (kinda)

Bet the farm moment

Concurrency

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Concurrency

Error encapsulation

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Concurrency

Error encapsulation

Fault detection

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Concurrency

Error encapsulation

Fault detection

Fault identification

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Concurrency

Error encapsulation

Fault detection

Fault identification

Code upgrade

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Concurrency

Error encapsulation

Fault detection

Fault identification

Code upgrade

Stable Storage

The Big SixFrom http://www.erlang.org/download/armstrong_thesis_2003.pdf

Erlang

Erlang

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

A System has States

States transition

Finite State Machines

A System has States

States transition

Transitions are Atomic

Finite State Machines

A System has States

States transition

Transitions are Atomic

Events at Entry and Exit

Finite State Machines

Everything is an FSM

Finite State Machines

Everything is an FSM

Finite State Machines

Everything is an FSM

Finite State Machines

Voice Response

Finite State Machines

Voice Response

Finite State Machines

Voice Response

Finite State Machines

Encapsulation

Call Routing

Finite State Machines

Templates are your friend

So are BIG sheets of paper

Think “Real World”

The Bottom Line