82
{ Erlang and gen_fsm @dieswaytoofast (V.P. Ubiquiti Networks)

Finite State Machines - Why the fear?

Embed Size (px)

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

Page 1: Finite State Machines - Why the fear?

{

Erlang and gen_fsm

@dieswaytoofast (V.P. Ubiquiti Networks)

Page 2: Finite State Machines - Why the fear?
Page 3: Finite State Machines - Why the fear?

The Business

Page 4: Finite State Machines - Why the fear?
Page 5: Finite State Machines - Why the fear?

The Metrics

Page 6: Finite State Machines - Why the fear?

Phone Calls per Second

The Metrics

Page 7: Finite State Machines - Why the fear?

Phone Calls per Second

The Metrics

Page 8: Finite State Machines - Why the fear?

Simultaneous Phone Calls

The Metrics

Page 9: Finite State Machines - Why the fear?

Simultaneous Phone Calls

The Metrics

Page 10: Finite State Machines - Why the fear?

HTTP API requests

The Metrics

Page 11: Finite State Machines - Why the fear?

HTTP API requests

The Metrics

Page 12: Finite State Machines - Why the fear?

Self-hosted (kinda)

Page 13: Finite State Machines - Why the fear?

Voice Response

Call Handling

Page 14: Finite State Machines - Why the fear?

Call Routing

Call Handling

Page 15: Finite State Machines - Why the fear?
Page 16: Finite State Machines - Why the fear?

Self-hosted (kinda)

Bet the farm moment

Page 17: Finite State Machines - Why the fear?
Page 18: Finite State Machines - Why the fear?
Page 19: Finite State Machines - Why the fear?

Concurrency

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

Page 20: Finite State Machines - Why the fear?

Concurrency

Error encapsulation

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

Page 21: Finite State Machines - Why the fear?

Concurrency

Error encapsulation

Fault detection

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

Page 22: Finite State Machines - Why the fear?

Concurrency

Error encapsulation

Fault detection

Fault identification

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

Page 23: Finite State Machines - Why the fear?

Concurrency

Error encapsulation

Fault detection

Fault identification

Code upgrade

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

Page 24: Finite State Machines - Why the fear?

Concurrency

Error encapsulation

Fault detection

Fault identification

Code upgrade

Stable Storage

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

Page 25: Finite State Machines - Why the fear?

Erlang

Page 26: Finite State Machines - Why the fear?

Erlang

Page 27: Finite State Machines - Why the fear?

gen_server

Behaviours

Page 28: Finite State Machines - Why the fear?

gen_server

gen_tcp

Behaviours

Page 29: Finite State Machines - Why the fear?

gen_server

gen_tcp

gen_event

Behaviours

Page 30: Finite State Machines - Why the fear?

gen_server

gen_tcp

gen_event

gen_fsm

Behaviours

Page 31: Finite State Machines - Why the fear?

gen_server

gen_tcp

gen_event

gen_fsm

Behaviours

Page 32: Finite State Machines - Why the fear?

gen_server

gen_tcp

gen_event

gen_fsm

Behaviours

Page 33: Finite State Machines - Why the fear?

A System has States

Finite State Machines

Page 34: Finite State Machines - Why the fear?
Page 35: Finite State Machines - Why the fear?

A System has States

States transition

Finite State Machines

Page 36: Finite State Machines - Why the fear?
Page 37: Finite State Machines - Why the fear?

A System has States

States transition

Transitions are Atomic

Finite State Machines

Page 38: Finite State Machines - Why the fear?
Page 39: Finite State Machines - Why the fear?

A System has States

States transition

Transitions are Atomic

Events at Entry and Exit

Finite State Machines

Page 40: Finite State Machines - Why the fear?
Page 41: Finite State Machines - Why the fear?
Page 42: Finite State Machines - Why the fear?
Page 43: Finite State Machines - Why the fear?
Page 44: Finite State Machines - Why the fear?
Page 45: Finite State Machines - Why the fear?
Page 46: Finite State Machines - Why the fear?
Page 47: Finite State Machines - Why the fear?
Page 48: Finite State Machines - Why the fear?
Page 49: Finite State Machines - Why the fear?
Page 50: Finite State Machines - Why the fear?
Page 51: Finite State Machines - Why the fear?
Page 52: Finite State Machines - Why the fear?
Page 53: Finite State Machines - Why the fear?
Page 54: Finite State Machines - Why the fear?
Page 55: Finite State Machines - Why the fear?
Page 56: Finite State Machines - Why the fear?
Page 57: Finite State Machines - Why the fear?
Page 58: Finite State Machines - Why the fear?
Page 59: Finite State Machines - Why the fear?
Page 60: Finite State Machines - Why the fear?
Page 61: Finite State Machines - Why the fear?
Page 62: Finite State Machines - Why the fear?
Page 63: Finite State Machines - Why the fear?
Page 64: Finite State Machines - Why the fear?
Page 65: Finite State Machines - Why the fear?
Page 66: Finite State Machines - Why the fear?
Page 67: Finite State Machines - Why the fear?
Page 68: Finite State Machines - Why the fear?
Page 69: Finite State Machines - Why the fear?
Page 70: Finite State Machines - Why the fear?
Page 71: Finite State Machines - Why the fear?
Page 72: Finite State Machines - Why the fear?

Everything is an FSM

Finite State Machines

Page 73: Finite State Machines - Why the fear?

Everything is an FSM

Finite State Machines

Page 74: Finite State Machines - Why the fear?

Everything is an FSM

Finite State Machines

Page 75: Finite State Machines - Why the fear?

Voice Response

Finite State Machines

Page 76: Finite State Machines - Why the fear?

Voice Response

Finite State Machines

Page 77: Finite State Machines - Why the fear?

Voice Response

Finite State Machines

Page 78: Finite State Machines - Why the fear?

Encapsulation

Page 79: Finite State Machines - Why the fear?

Call Routing

Finite State Machines

Page 80: Finite State Machines - Why the fear?
Page 81: Finite State Machines - Why the fear?

Templates are your friend

So are BIG sheets of paper

Think “Real World”

The Bottom Line

Page 82: Finite State Machines - Why the fear?