Whirlwind Tour of Erlang

Whirlwind Tour of Erlang

Erlang was designed from ground up to write scalable, fault-tolerant, distributed, non-stop, soft-realtime applications. Everything in the language, runtime and libraries supports these needs. It powers payment providers, game servers, telephone exchanges and also Facebook Chat. In this presentation, we will go on a whirlwind tour of how Erlang differs from other languages and where to best use it.

64afebe5db598b0b043f35560bf940df?s=128

Martin Schürrer

September 13, 2013
Tweet

Transcript

  1. for highly-available, scalable systems

  2. Erlang is a programming language used to build massively scalable

    soft real-time systems with requirements on high availability.
  3. None
  4. None
  5. BEAM OTP Process Node Message spawn

  6. Operating System Operating System BEAM Base Class Library OTP .NET

    Framework CLR ERTS STDLIB kernel Erlang Elixir C# F# .NET Erlang/OTP
  7. OS Process Erlang VM Erlang Node NOT Erlang Process Erlang

    Process Actor light-weight Thread NOT OS Process
  8. Heap Mailbox Stack

  9. **********" **********" **********" **********" **********" **********" **********" **********" **********" **********"

    **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" **********" One$.NET$4.0$Thread$$ (allocates$one$megabyte)$ One$Erlang$Process$(allocates$one$kilobyte)$ *$ @bryan_hunter
  10. Heap Mailbox Stack Heap Mailbox Stack Heap Mailbox Stack Heap

    Mailbox Stack Heap Mailbox Stack
  11. Heap Mailbox Stack Heap Mailbox Stack Heap Mailbox Stack Heap

    Mailbox Stack Heap Mailbox Stack Message Heap Mailbox Stack
  12. Heap Mailbox Stack Message

  13. Mailbox Message 1 Message 2 Message 3 calculate something send

    message to P1 send message to P2 wait for incoming message calculate something send message to P1 wait for incoming message
  14. wait for incoming message handle message by sending more messages

    and then waiting for answers from other processes send an answer message back
  15. Who sends/receives messages? •other processes (obviously) •open files •open sockets

    •external programs (Ports) •Erlang VM notifications •a process you watched died •a remote node you watched died
  16. Who sends/receives messages? •open files •“write this” •“read 15 bytes”

    -> “here are 15 bytes” •open sockets •“write this” •“some bytes just arrived” •external programs (Ports) •STDOUT/STDIN/STDERR
  17. async  Task<string>  GetStringAsync()  {    string  output  =  ""  

     for  (int  i=0;  i<999999999999;  i++)  {        output  +=  "i'm  sure  this  will  be  fast";    }    return  output; } async  Task<int>  NotSoAsync()  {      Task<string>  getStringTask  =  GetStringAsync();    DoIndependentWork();    string  long  =  await  getStringTask;    return  long; }
  18. calculate(something) calculate(something) calculate(something) calculate(something) calculate(something) calculate(something) calculate(something)

  19. 2000 reductions left: calculate(something) 1000 reductions left: still calculating(something) 0

    reductions left: suspend process run next process green threads = cheap context switching
  20. Supervisors

  21. None
  22. OTP Behaviours gen_server gen_fsm gen_event

  23. None
  24. Conn 1 Conn 2 Conn 3 Conn 4 Conn 5

    Player 1 Player 2 Player 3 Player 4 Player 5 Table 1 Table 2 Game 1 Game 5
  25. Distributed Erlang

  26. Heap Mailbox Stack Heap Mailbox Stack Heap Mailbox Stack Heap

    Mailbox Stack Heap Mailbox Stack Heap Mailbox Stack
  27. None
  28. speakerrate.com/talks/25881 @MSch martin@apoch.io APOCH