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

Introduction to Erlang

Introduction to Erlang

Michał Ślaski

October 28, 2014
Tweet

More Decks by Michał Ślaski

Other Decks in Programming

Transcript

  1. Introduction  to  Erlang Michał  Ślaski          @michalslaski

      ! ! !      AKAI  Camp  Backend,  Poznań,  28.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. Erlang  properties Declarative   • Functional  programming  language   •

    high  abstraction  level   • pattern  matching   • concise  and  readable  programs
  8. Erlang  properties  -­‐  functions Modules & Functions -module(demo). -export([double/1]). %

    This is a comment. % Everything after '%' is ignored. double(X) -> times(X, 2). times(X, N) -> X * N.
  9. Erlang  properties Concurrency   • light-­‐weight  processes  (actor  model)  

    • highly  scalable
 
 Soft  real-­‐time   • response  times  in  the  order  of  milliseconds   • per  process  garbage  collection
  10. Erlang  properties  -­‐  processes Pid = spawn(M, F, A) receive!

    {msg, From} ->! From ! ok! end Pid ! {msg, self()}
  11. Erlang  properties  -­‐  processes Pid = spawn(M, F, A) receive!

    {msg, From} ->! From ! ok! end Pid ! {msg, self()} ok
  12. Erlang  properties Robustness   • simple  and  consistent  error  recovery

      • supervision  hierarchies   • program  for  the  correct  case   • let  it  crash
  13. Erlang  properties  -­‐  distribution cat dog flea bird nodes() =

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

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

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

  16. Erlang  properties Hot  code  loading   • easily  change  code

     in  a  running  system   • enables  non-­‐stop  operation   • simplifies  testing
 SMP  support   • takes  advantage  of  multiple  CPU  architectures

  17. Erlang  properties Hot  code  loading   • easily  change  code

     in  a  running  system   • enables  non-­‐stop  operation   • simplifies  testing
 SMP  support   • takes  advantage  of  multiple  CPU  architectures
 Erlang  Shell   • access  from  remote  nodes
  18. Erlang  properties External  interfaces   • "Ports"  to  the  outside

     world
 behave  as  Erlang  processes
 Portability   • Erlang  runs  on  Unix,  Linux,  Mac  OS  X,  Windows   • RaspberryPi  and  Parallella  
  19. Demo  -­‐  SMP $ erl -smp disable Erlang/OTP 17 [erts-6.1]

    [source-d2a4c20] [async-threads:10]
 [hipe] [kernel-poll:false] ! Eshell V6.1 (abort with ^G) 
 1> F = fun(Int) -> pmap:factorial(Int) end. #Fun<erl_eval.6.90072148>
 2> timer:tc(lists, map, [F,lists:seq(1, 5000)]). {12570092, [1,2,6,24,120,720,5040,40320,362880,3628800|...]} 
 3> timer:tc(pmap, pmap, [F,lists:seq(1, 5000)]). {21511918, [1,2,6,24,120,720,5040,40320,362880,3628800|...]} 
 4> element(2, v(2)) == element(2, v(3)). true
  20. Demo  -­‐  SMP $ erl -smp enable Erlang/OTP 17 [erts-6.1]

    [source-d2a4c20] [smp:4:4]
 [async-threads:10] [hipe] [kernel-poll:false] ! Eshell V6.1 (abort with ^G) ! 1> F = fun(Int) -> pmap:factorial(Int) end. #Fun<erl_eval.6.90072148> ! 2> timer:tc(lists, map, [F,lists:seq(1, 5000)]). {12535610, [1,2,6,24,120,720,5040,40320,362880,3628800|...]} ! 3> timer:tc(pmap, pmap, [F,lists:seq(1, 5000)]). {9159734, [1,2,6,24,120,720,5040,40320,362880,3628800|...]}
  21. Open  source  projects • RabbitMQ  message  broker  
 • MongooseIM

     XMPP  server
 • Riak  database
 • CouchDB  database
  22. Erlang  community Erlang  Central   • www.erlangcentral.org
 Erlang  Factory  

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

  23. Erlang  community Erlang  Central   • www.erlangcentral.org
 Erlang  Factory  

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