Lessons from Erlang

69639a461e92e590acdc1b554934bd8d?s=47 Michał Ślaski
October 31, 2014
240

Lessons from Erlang

In this talk we will discuss thinking in a concurrent programming language along with the problems it has to solve. We will take a look at the real tools Erlang gives you to write highly-available systems that let you sleep through the night: dynamic tracing and remote REPL. We'll see how these tools are used.

69639a461e92e590acdc1b554934bd8d?s=128

Michał Ślaski

October 31, 2014
Tweet

Transcript

  1. Lessons    From    Erlang Michał  Ślaski      

     @michalslaski   ! ! !      PolyConf,  Poznań,  31.10.2014
  2. Erlang  timeline  and  my  background

  3. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!)
  4. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!) • I  was  six  years  old

  5. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!) • I  was  six  years  old
 Released  as  open  source  in  1998
  6. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!) • I  was  six  years  old
 Released  as  open  source  in  1998 • I  started  computer  science  at  AGH  2  years  later

  7. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!) • I  was  six  years  old
 Released  as  open  source  in  1998 • I  started  computer  science  at  AGH  2  years  later
 Gains  SMP  support  in  2005
  8. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

     software  lab  1987  (!) • I  was  six  years  old
 Released  as  open  source  in  1998 • I  started  computer  science  at  AGH  2  years  later
 Gains  SMP  support  in  2005 • I  just  graduated  and  joined  Erlang  Solutions
  9. Maintenance  vs.  Development

  10. Maintenance  vs.  Development Maintenance  may  span  for  20  years,
 whereas

     development  may  be  1-­‐2  years.     ! ! ! ! ! ! ! ! ! Schach,  R.,  Software  Engineering
 Fourth  Edition,  McGraw-­‐Hill,  Boston,  MA  1999

  11. Erlang  properties

  12. Erlang  properties OTP  behaviours   • set  of  design  patterns

      • client-­‐server,  fsm,  supervisor   • application,  release

  13. Erlang  properties OTP  behaviours   • set  of  design  patterns

      • client-­‐server,  fsm,  supervisor   • application,  release
 What  for?   • consistent  maintenance  procedures   • one  tar  ball  artefact
  14. Erlang  OTP  releases $ ls -l ../abacus.tar -rw-r--r-- 1 ms

    staff 12331520 Oct 31 12:01 abacus.tar ! $ ls -1 bin erts-6.1 lib releases ! $ ./bin/abacus Erlang/OTP 17 [erts-6.1] [smp:4:4] 
 [async-threads:10] [kernel-poll:false] ! Eshell V6.1 (abort with ^G) (abacus@127.0.0.1)1> github.com/michalslaski/erlang-­‐workshop
  15. Erlang  properties

  16. Erlang  properties Robustness   • simple  and  consistent  error  recovery

      • supervision  hierarchies   • program  for  the  correct  case   • let  it  crash

  17. Erlang  properties Robustness   • simple  and  consistent  error  recovery

      • supervision  hierarchies   • program  for  the  correct  case   • let  it  crash
 What  for?   • resilient  to  bugs  and  failures
  18. Erlang  properties  -­‐  supervision  tree

  19. Erlang  properties  -­‐  supervision  tree

  20. Erlang  properties  -­‐  supervision  tree

  21. Erlang  properties  -­‐  supervision  tree supervisor

  22. Erlang  properties  -­‐  supervision  tree supervisor worker

  23. Erlang  properties  -­‐  supervision  tree supervisor worker

  24. Erlang  properties  -­‐  supervision  tree supervisor worker

  25. Erlang  properties  -­‐  supervision  tree supervisor worker

  26. Erlang  properties

  27. Erlang  properties Distribution   • explicit  or  transparent  distribution  

    • network-­‐aware  runtime  system

  28. Erlang  properties Distribution   • explicit  or  transparent  distribution  

    • network-­‐aware  runtime  system
 What  for?   • remote  Erlang  shell  (REPL)   • remote  observing  tools
  29. Erlang  properties  -­‐  distribution

  30. Erlang  properties  -­‐  distribution cat

  31. Erlang  properties  -­‐  distribution cat flea

  32. Erlang  properties  -­‐  distribution cat flea nodes() = [cat@home, flea@home]

  33. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

    [cat@home, flea@home]
  34. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

    [cat@home, flea@home] nodes() = [dog@home, bird@home]
  35. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

    [cat@home, flea@home] nodes() = [dog@home, bird@home]
  36. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

    [cat@home, flea@home, dog@work, bird@work]
  37. entop  vs.  top

  38. entop  vs.  top

  39. entop  vs.  top https://github.com/mazenharake/entop

  40. Erlang  properties

  41. Erlang  properties Hot  code  loading   • easily  change  code

     in  a  running  system   • enables  non-­‐stop  operation   • simplifies  testing

  42. Erlang  properties Hot  code  loading   • easily  change  code

     in  a  running  system   • enables  non-­‐stop  operation   • simplifies  testing
 What  for?   • shorter  development  cycle   • non-­‐stop  operations
  43. Erlang  properties

  44. Erlang  properties Tracing  in  Erlang  VM   • Tracing  is

     turned  on/off  per  process   • function  calls,  message  passing,  GC,  scheduler

  45. Erlang  properties Tracing  in  Erlang  VM   • Tracing  is

     turned  on/off  per  process   • function  calls,  message  passing,  GC,  scheduler
 What  for?   • live  debugging   • no  need  to  instrument  code  and  recompile
  46. Erlang  tracing courtesy  of  Mats  Cronqvist

  47. Erlang  tracing  calls

  48. Erlang  tracing  calls redbug  -­‐  github.com/massemanet/eper   • tracing  tool

     built  on  top  of  erlang:trace/3
  49. Erlang  tracing  calls redbug  -­‐  github.com/massemanet/eper   • tracing  tool

     built  on  top  of  erlang:trace/3 1> redbug:start("lists:seq(X,Y) -> return"). {30,1}! 2> lists:seq(1,5).! [1,2,3,4,5]! ! % 12:32:17 <0.32.0>({erlang,apply,2})! % lists:seq(1, 5)! ! % 12:32:17 <0.32.0>({erlang,apply,2})! % lists:seq/2 -> [1,2,3,4,5]
  50. Flame  Graphs  for  Erlang  -­‐  eflame

  51. Flame  Graphs  for  Erlang  -­‐  eflame github.com/proger/eflame   • as

     stacks  are  collected  through  tracing,
 blocking  calls  are  noticed  and  are  drawn  in  blue
  52. Flame  Graphs  for  Erlang  -­‐  eflame github.com/proger/eflame   • as

     stacks  are  collected  through  tracing,
 blocking  calls  are  noticed  and  are  drawn  in  blue
  53. What’s  next?

  54. Erlang  the  Movie

  55. Erlang  the  Movie

  56. Erlang  the  Movie  II

  57. Erlang  the  Movie  II

  58. Open  source  projects

  59. Open  source  projects • RabbitMQ  message  broker  


  60. Open  source  projects • RabbitMQ  message  broker  
 • MongooseIM

     XMPP  server

  61. Open  source  projects • RabbitMQ  message  broker  
 • MongooseIM

     XMPP  server
 • Riak  database

  62. Open  source  projects • RabbitMQ  message  broker  
 • MongooseIM

     XMPP  server
 • Riak  database
 • CouchDB  database
  63. Erlang  Community

  64. Erlang  Community Erlang  Central   • www.erlangcentral.org


  65. Erlang  Community Erlang  Central   • www.erlangcentral.org
 Erlang  Factory  

    • Berlin,  December  4   • San  Francisco,  March  26-­‐27

  66. Erlang  Community Erlang  Central   • www.erlangcentral.org
 Erlang  Factory  

    • Berlin,  December  4   • San  Francisco,  March  26-­‐27
 Lambda  Days   • Kraków,  February  26-­‐27
  67. Lambda  Days  Call  for  Papers

  68. Lambda  Days  Call  for  Papers SUBMIT  YOUR  TALK

  69. Questions? ! Michał  Ślaski          @michalslaski