68
Lessons From Erlang Michał Ślaski @michalslaski 4Developers, 20.04.2015

4Developers 2015: Lessons for Erlang VM - Michał Ślaski

  • Upload
    proidea

  • View
    95

  • Download
    0

Embed Size (px)

Citation preview

Lessons    From    Erlang

Michał  Ślaski        @michalslaski  !

!

!

     4Developers,  20.04.2015

Erlang  timeline  and  my  background

Erlang  timeline  and  my  background

Started  out  in  the  Ericsson  software  lab  1987  (!)

Erlang  timeline  and  my  background

Started  out  in  the  Ericsson  software  lab  1987  (!)• I  was  six  years  old

Erlang  timeline  and  my  background

Started  out  in  the  Ericsson  software  lab  1987  (!)• I  was  six  years  old

Released  as  open  source  in  1998

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

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

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

Maintenance  vs.  Development

Maintenance  vs.  Development

Maintenance  may  span  for  20  years,whereas  development  may  be  1-­‐2  years.    

!!!!!!

!!

!Schach,  R.,  Software  EngineeringFourth  Edition,  McGraw-­‐Hill,  Boston,  MA  1999

Erlang  properties

Erlang  properties

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

Erlang  properties

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

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

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

Erlang  properties

Erlang  properties

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

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

Erlang  properties  -­‐  supervision  tree

Erlang  properties  -­‐  supervision  tree

Erlang  properties  -­‐  supervision  tree

Erlang  properties  -­‐  supervision  tree

supervisor

Erlang  properties  -­‐  supervision  tree

supervisor

worker

Erlang  properties  -­‐  supervision  tree

supervisor

worker

Erlang  properties  -­‐  supervision  tree

supervisor

worker

Erlang  properties  -­‐  supervision  tree

supervisor

worker

Erlang  properties

Erlang  properties

Distribution  • explicit  or  transparent  distribution  • network-­‐aware  runtime  system

Erlang  properties

Distribution  • explicit  or  transparent  distribution  • network-­‐aware  runtime  system

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

Erlang  properties  -­‐  distribution

Erlang  properties  -­‐  distribution

cat

Erlang  properties  -­‐  distribution

cat

flea

Erlang  properties  -­‐  distribution

cat

fleanodes() =

[cat@home, flea@home]

Erlang  properties  -­‐  distribution

cat dog

flea birdnodes() =

[cat@home, flea@home]

Erlang  properties  -­‐  distribution

cat dog

flea birdnodes() =

[cat@home, flea@home]nodes() =

[dog@home, bird@home]

Erlang  properties  -­‐  distribution

cat dog

flea birdnodes() =

[cat@home, flea@home]nodes() =

[dog@home, bird@home]

Erlang  properties  -­‐  distribution

cat dog

flea birdnodes() =

[cat@home, flea@home, dog@work, bird@work]

entop  vs.  top

entop  vs.  top

entop  vs.  top

https://github.com/mazenharake/entop

Erlang  properties

Erlang  properties

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

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

Erlang  properties

Erlang  properties

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

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

Erlang  tracing

courtesy  of  Mats  Cronqvist

Erlang  tracing  calls

Erlang  tracing  calls

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

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]

Flame  Graphs  for  Erlang  -­‐  eflame

Flame  Graphs  for  Erlang  -­‐  eflame

github.com/proger/eflame  • as  stacks  are  collected  through  tracing,blocking  calls  are  noticed  and  are  drawn  in  blue

Flame  Graphs  for  Erlang  -­‐  eflame

github.com/proger/eflame  • as  stacks  are  collected  through  tracing,blocking  calls  are  noticed  and  are  drawn  in  blue

What’s  next?

Erlang  the  Movie

Erlang  the  Movie

Erlang  the  Movie  II

Erlang  the  Movie  II

Open  source  projects

Open  source  projects

• RabbitMQ  message  broker  

Open  source  projects

• RabbitMQ  message  broker  

• MongooseIM  XMPP  server

Open  source  projects

• RabbitMQ  message  broker  

• MongooseIM  XMPP  server

• Riak  database

Open  source  projects

• RabbitMQ  message  broker  

• MongooseIM  XMPP  server

• Riak  database

• CouchDB  database

Erlang  Community

Erlang  Community

Erlang  Central  • www.erlangcentral.org

Erlang  Community

Erlang  Central  • www.erlangcentral.org

Erlang  User  Conference  • Stockholm,  June  2015

Erlang  Community

Erlang  Central  • www.erlangcentral.org

Erlang  User  Conference  • Stockholm,  June  2015

Erlang  Community

Erlang  Central  • www.erlangcentral.org

Erlang  User  Conference  • Stockholm,  June  2015

Lambda  Academy  • lambdaacademy.org,  March-­‐June  2015

Questions?

!

Michał  Ślaski          @michalslaski