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

Lessons from Erlang

Avatar for Michał Ślaski Michał Ślaski
October 31, 2014
330

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.

Avatar for Michał Ślaski

Michał Ślaski

October 31, 2014
Tweet

More Decks by Michał Ślaski

Transcript

  1. Lessons    From    Erlang Michał  Ślaski      

     @michalslaski   ! ! !      PolyConf,  Poznań,  31.10.2014
  2. Erlang  timeline  and  my  background Started  out  in  the  Ericsson

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

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

     software  lab  1987  (!) • I  was  six  years  old
 Released  as  open  source  in  1998
  4. 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

  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 • I  started  computer  science  at  AGH  2  years  later
 Gains  SMP  support  in  2005
  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
 Gains  SMP  support  in  2005 • I  just  graduated  and  joined  Erlang  Solutions
  7. 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

  8. Erlang  properties OTP  behaviours   • set  of  design  patterns

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

  9. Erlang  properties OTP  behaviours   • set  of  design  patterns

      • client-­‐server,  fsm,  supervisor   • application,  release
 What  for?   • consistent  maintenance  procedures   • one  tar  ball  artefact
  10. 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
  11. Erlang  properties Robustness   • simple  and  consistent  error  recovery

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

  12. 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
  13. Erlang  properties Distribution   • explicit  or  transparent  distribution  

    • network-­‐aware  runtime  system
 What  for?   • remote  Erlang  shell  (REPL)   • remote  observing  tools
  14. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

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

    [cat@home, flea@home] nodes() = [dog@home, bird@home]
  16. Erlang  properties Hot  code  loading   • easily  change  code

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

  17. 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
  18. Erlang  properties Tracing  in  Erlang  VM   • Tracing  is

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

  19. 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
  20. 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]
  21. Flame  Graphs  for  Erlang  -­‐  eflame github.com/proger/eflame   • as

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

     stacks  are  collected  through  tracing,
 blocking  calls  are  noticed  and  are  drawn  in  blue
  23. Open  source  projects • RabbitMQ  message  broker  
 • MongooseIM

     XMPP  server
 • Riak  database
 • CouchDB  database
  24. Erlang  Community Erlang  Central   • www.erlangcentral.org
 Erlang  Factory  

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

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

    • Berlin,  December  4   • San  Francisco,  March  26-­‐27
 Lambda  Days   • Kraków,  February  26-­‐27