Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lessons from Erlang

Michał Ślaski
October 31, 2014
310

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.

Michał Ślaski

October 31, 2014
Tweet

Transcript

  1. Lessons    From    Erlang
    Michał  Ślaski        @michalslaski  
    !
    !
    !
         PolyConf,  Poznań,  31.10.2014

    View full-size slide

  2. Erlang  timeline  and  my  background

    View full-size slide

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

    View full-size slide

  4. Erlang  timeline  and  my  background
    Started  out  in  the  Ericsson  software  lab  1987  (!)
    • I  was  six  years  old


    View full-size slide

  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

    View full-size slide

  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


    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  9. Maintenance  vs.  Development

    View full-size slide

  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


    View full-size slide

  11. Erlang  properties

    View full-size slide

  12. Erlang  properties
    OTP  behaviours  
    • set  of  design  patterns  
    • client-­‐server,  fsm,  supervisor  
    • application,  release


    View full-size slide

  13. Erlang  properties
    OTP  behaviours  
    • set  of  design  patterns  
    • client-­‐server,  fsm,  supervisor  
    • application,  release

    What  for?  
    • consistent  maintenance  procedures  
    • one  tar  ball  artefact

    View full-size slide

  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)
    ([email protected])1>
    github.com/michalslaski/erlang-­‐workshop

    View full-size slide

  15. Erlang  properties

    View full-size slide

  16. Erlang  properties
    Robustness  
    • simple  and  consistent  error  recovery  
    • supervision  hierarchies  
    • program  for  the  correct  case  
    • let  it  crash


    View full-size slide

  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

    View full-size slide

  18. Erlang  properties  -­‐  supervision  tree

    View full-size slide

  19. Erlang  properties  -­‐  supervision  tree

    View full-size slide

  20. Erlang  properties  -­‐  supervision  tree

    View full-size slide

  21. Erlang  properties  -­‐  supervision  tree
    supervisor

    View full-size slide

  22. Erlang  properties  -­‐  supervision  tree
    supervisor
    worker

    View full-size slide

  23. Erlang  properties  -­‐  supervision  tree
    supervisor
    worker

    View full-size slide

  24. Erlang  properties  -­‐  supervision  tree
    supervisor
    worker

    View full-size slide

  25. Erlang  properties  -­‐  supervision  tree
    supervisor
    worker

    View full-size slide

  26. Erlang  properties

    View full-size slide

  27. Erlang  properties
    Distribution  
    • explicit  or  transparent  distribution  
    • network-­‐aware  runtime  system


    View full-size slide

  28. Erlang  properties
    Distribution  
    • explicit  or  transparent  distribution  
    • network-­‐aware  runtime  system

    What  for?  
    • remote  Erlang  shell  (REPL)  
    • remote  observing  tools

    View full-size slide

  29. Erlang  properties  -­‐  distribution

    View full-size slide

  30. Erlang  properties  -­‐  distribution
    cat

    View full-size slide

  31. Erlang  properties  -­‐  distribution
    cat
    flea

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  37. entop  vs.  top

    View full-size slide

  38. entop  vs.  top

    View full-size slide

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

    View full-size slide

  40. Erlang  properties

    View full-size slide

  41. Erlang  properties
    Hot  code  loading  
    • easily  change  code  in  a  running  system  
    • enables  non-­‐stop  operation  
    • simplifies  testing


    View full-size slide

  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

    View full-size slide

  43. Erlang  properties

    View full-size slide

  44. Erlang  properties
    Tracing  in  Erlang  VM  
    • Tracing  is  turned  on/off  per  process  
    • function  calls,  message  passing,  GC,  scheduler


    View full-size slide

  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

    View full-size slide

  46. Erlang  tracing
    courtesy  of  Mats  Cronqvist

    View full-size slide

  47. Erlang  tracing  calls

    View full-size slide

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

    View full-size slide

  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]

    View full-size slide

  50. Flame  Graphs  for  Erlang  -­‐  eflame

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  53. What’s  next?

    View full-size slide

  54. Erlang  the  Movie

    View full-size slide

  55. Erlang  the  Movie

    View full-size slide

  56. Erlang  the  Movie  II

    View full-size slide

  57. Erlang  the  Movie  II

    View full-size slide

  58. Open  source  projects

    View full-size slide

  59. Open  source  projects
    • RabbitMQ  message  broker  


    View full-size slide

  60. Open  source  projects
    • RabbitMQ  message  broker  

    • MongooseIM  XMPP  server


    View full-size slide

  61. Open  source  projects
    • RabbitMQ  message  broker  

    • MongooseIM  XMPP  server

    • Riak  database


    View full-size slide

  62. Open  source  projects
    • RabbitMQ  message  broker  

    • MongooseIM  XMPP  server

    • Riak  database

    • CouchDB  database

    View full-size slide

  63. Erlang  Community

    View full-size slide

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


    View full-size slide

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

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


    View full-size slide

  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

    View full-size slide

  67. Lambda  Days  Call  for  Papers

    View full-size slide

  68. Lambda  Days  Call  for  Papers
    SUBMIT  YOUR  TALK

    View full-size slide

  69. Questions?
    !
    Michał  Ślaski          @michalslaski

    View full-size slide