Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Finite State Machines - Why the fear?

2,981 views

Published on

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.

  • Be the first to comment

Finite State Machines - Why the fear?

  1. 1. { Erlang and gen_fsm @dieswaytoofast (V.P. Ubiquiti Networks)
  2. 2. The Business
  3. 3. The Metrics
  4. 4.  Phone Calls per Second The Metrics
  5. 5.  Phone Calls per Second The Metrics x 1000
  6. 6.  Simultaneous Phone Calls The Metrics
  7. 7.  Simultaneous Phone Calls The Metrics x 10,000
  8. 8.  HTTP API requests The Metrics
  9. 9.  HTTP API requests The Metrics x ∞
  10. 10.  Self-hosted (kinda)
  11. 11.  Voice Response Call Handling init Setup Call Get Caller Name Play Transfer Message Got Caller Name Dial
  12. 12.  Call Routing Call Handling dial_in Check Blacklist get_endpoint conference Play Error Hangupauto_attendant dial_in_fml conference
  13. 13. init Check node Check Blacklist Cancelled Blacklisted Next Endpoint Collections Unknown Move node Auto Attendant FML Voicemail FaxConference
  14. 14.  Self-hosted (kinda) Bet the farm moment
  15. 15. ERLANG!!!
  16. 16.  Concurrency The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  17. 17.  Concurrency  Error encapsulation The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  18. 18.  Concurrency  Error encapsulation  Fault detection The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  19. 19.  Concurrency  Error encapsulation  Fault detection  Fault identification The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  20. 20.  Concurrency  Error encapsulation  Fault detection  Fault identification  Code upgrade The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  21. 21.  Concurrency  Error encapsulation  Fault detection  Fault identification  Code upgrade  Stable Storage The Big Six From http://www.erlang.org/download/armstrong_thesis_2003.pdf
  22. 22. Erlang Concurrency Hell My Blue Heaven My Blue Heaven
  23. 23. Erlang Concurrency Hell My Blue Heaven Deep Problems My Blue Heaven Deep Problems
  24. 24.  gen_server Behaviours
  25. 25.  gen_server  gen_tcp Behaviours
  26. 26.  gen_server  gen_tcp  gen_event Behaviours
  27. 27.  gen_server  gen_tcp  gen_event  gen_fsm Behaviours
  28. 28.  gen_server  gen_tcp  gen_event  gen_fsm  … Behaviours
  29. 29.  gen_server  gen_tcp  gen_event  gen_fsm  … Behaviours
  30. 30.  A System has States Finite State Machines
  31. 31. asleepStart out of bed Coffee!!
  32. 32.  A System has States  States transition Finite State Machines
  33. 33. asleepStart out of bed Coffee!!
  34. 34.  A System has States  States transition  Transitions are Atomic Finite State Machines
  35. 35. asleepStart out of bed Coffee!! NOTHING HERE
  36. 36.  A System has States  States transition  Transitions are Atomic  Events at Entry and Exit Finite State Machines
  37. 37. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!!
  38. 38. asleepStart out of bed Coffee!!
  39. 39. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!!
  40. 40. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!!
  41. 41. asleepStart out of bed Coffee!!
  42. 42. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!! HUH?
  43. 43. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!!
  44. 44. asleepStart out of bed Riiiiiiiiing Brush Teeth Coffee!! W 00t!
  45. 45. Un- Auth Start Token Req. Stop
  46. 46. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  47. 47. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  48. 48. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  49. 49. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  50. 50. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  51. 51. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  52. 52. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  53. 53. Un- Auth Start Token Req. Stop Get Request Token Get Access Token Request Token Access Token
  54. 54.  Everything is an FSM Finite State Machines
  55. 55.  Everything is an FSM Finite State Machines COM PLEXITY?
  56. 56.  Everything is an FSM Finite State Machines ENCAPSULATION!
  57. 57.  Voice Response Finite State Machines init Setup Call Get Caller Name Play Transfer Message Got Caller Name Dial
  58. 58.  Voice Response Finite State Machines init Setup Call Get Caller Name Play Transfer Message Got Caller Name Dial
  59. 59.  Voice Response Finite State Machines init Setup Call Get Caller Name Play Transfer Message Got Caller Name Dial ENCAPSULATION!
  60. 60. Encapsulation Concurrency Hell My Blue Heaven Deep Problems My Blue Heaven Deep Problems
  61. 61.  Call Routing Finite State Machines dial_in Check Blacklist get_endpoint conference Play Error Hangupauto_attendant dial_in_fml conference
  62. 62. init Check node Check Blacklist Cancelled Blacklisted Next Endpoint Collections Unknown Move node Auto Attendant FML Voicemail FaxConference
  63. 63.  Templates are your friend  So are BIG sheets of paper  Think “Real World” The Bottom Line

×