SlideShare a Scribd company logo
Erlang in a (real) nutshell

        Lu´ Ferreira
          ıs

      Universidade do Minho
        Semana da Lei II

      zamith.28@gmail.com

        July 13, 2010
What is Erlang?




    Distributed




                  Lu´ Ferreira
                    ıs           Erlang in a (real) nutshell
What is Erlang?




    Distributed
    Concurrent




                  Lu´ Ferreira
                    ıs           Erlang in a (real) nutshell
What is Erlang?




    Distributed
    Concurrent
    Fault-tolerant




                     Lu´ Ferreira
                       ıs           Erlang in a (real) nutshell
What is Erlang?




    Distributed
    Concurrent
    Fault-tolerant
    Functional based




                       Lu´ Ferreira
                         ıs           Erlang in a (real) nutshell
Why use Erlang?

  NO
       Number-crunching applications
       Graphics intesive systems




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Why use Erlang?

  NO
        Number-crunching applications
        Graphics intesive systems




  YES
        High-level, concurrent, robust, soft real-time system that will
        scale
        Make full use of multicore processors
        Integrate with components written in other languages




                            Lu´ Ferreira
                              ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task




                       Lu´ Ferreira
                         ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack




                        Lu´ Ferreira
                          ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance
      Functional/single-assignment




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance
      Functional/single-assignment
      Asynchronous message passing (send and pray) - Any Erlang
      value




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance
      Functional/single-assignment
      Asynchronous message passing (send and pray) - Any Erlang
      value
      OS independent




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance
      Functional/single-assignment
      Asynchronous message passing (send and pray) - Any Erlang
      value
      OS independent
      Messages retrieved selectively from the mailbox




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Some of the essential characteristics

      Low memory overhead per process/task
      Thousands of processes - Own memory space, heap and stack
      No ”global” errors. Stop errors propagating
      Predictable performance
      Functional/single-assignment
      Asynchronous message passing (send and pray) - Any Erlang
      value
      OS independent
      Messages retrieved selectively from the mailbox
      Message passing by copy of data




                         Lu´ Ferreira
                           ıs           Erlang in a (real) nutshell
Sequential Erlang




  Sort
  sort([Pivot|T]) ->
      sort([X||X <- T, X =< Pivot]) ++
      [Pivot] ++ sort([X||X <- T, X >= Pivot]);
  sort([]) -> [].




                     Lu´ Ferreira
                       ıs           Erlang in a (real) nutshell
Concurrent Erlang


  Area Server
  -module(server).
  -export([start/0]).

  start() ->
      register(server,spawn(fun() -> loop(0) end)).
  loop(Tot) ->
      receive
          {Pid, {square, X}} ->
              Pid ! X*X,
              loop(Tot + X*X);
          {Pid, {rectangle,[X,Y]}} ->
              Pid ! X*Y,
              loop(Tot + X*Y);
          {Pid, areas} ->
              Pid ! Tot,
              loop(Tot)
      end.



                              Lu´ Ferreira
                                ıs           Erlang in a (real) nutshell
Concurrent Erlang



  Area Client


  -module(client).
  -export([square/1]).

  square(Val) ->
      server ! {self(),{square,Val}},
  receive
      Area ->
          io:format("Area: ~p~n",[Val])
  end.


                     Lu´ Ferreira
                       ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes                     Exception handle
    Hot code replacement                 try return(X) when
    Generic behaviours                   is integer(X) ->
    ...                                     try return error(X) of
                                              Val -> {normal,Val}
                                         catch
                                            exit:Reason ->
                                              {exit,Reason}
                                            throw:Throw ->
                                              {throw,Throw}
                                            error:Error ->
                                              {error,Error}
                                         end.


                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes                     Trap exits
    Hot code replacement                 process flag(trap exits,
    Generic behaviours                   true),
    ...                                  P = spawn link(Node, Mod,
                                         Func, Args),
                                         receive
                                            {’EXIT’, P, Why}->
                                               Actions;
                                            ...
                                         end




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes
    Hot code replacement
    Generic behaviours
    ...



                                                                          worker



                                                                       supervisor




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes
    Hot code replacement
    Generic behaviours
    ...




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes
    Hot code replacement
    Generic behaviours
    ...




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell
Other features

    Fault tolerance (catch/throw)
    Trapping exits
    Linked processes
    Hot code replacement
    Generic behaviours
    ...




                          Lu´ Ferreira
                            ıs           Erlang in a (real) nutshell

More Related Content

PDF
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
PDF
Keynote joearmstrong
PDF
Erlang in 10 minutes
KEY
Osdc 2011 michael_neale
ODP
An introduction to erlang
PDF
Elixir
PDF
Erlang, an overview
PDF
Erlang Message Passing Concurrency, For The Win
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Keynote joearmstrong
Erlang in 10 minutes
Osdc 2011 michael_neale
An introduction to erlang
Elixir
Erlang, an overview
Erlang Message Passing Concurrency, For The Win

Similar to Presentation (7)

PDF
Introduction To Erlang Final
PDF
Webinar: Live without Exception in Rust
PDF
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
PPTX
Intro to Functional Programming
KEY
LISP: How I Learned To Stop Worrying And Love Parantheses
PDF
Joe armstrong erlanga_languageforprogrammingreliablesystems
PDF
You shall not get excited
Introduction To Erlang Final
Webinar: Live without Exception in Rust
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
Intro to Functional Programming
LISP: How I Learned To Stop Worrying And Love Parantheses
Joe armstrong erlanga_languageforprogrammingreliablesystems
You shall not get excited
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
August Patch Tuesday
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
Mushroom cultivation and it's methods.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Tartificialntelligence_presentation.pptx
PPTX
TLE Review Electricity (Electricity).pptx
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
OMC Textile Division Presentation 2021.pptx
A novel scalable deep ensemble learning framework for big data classification...
WOOl fibre morphology and structure.pdf for textiles
August Patch Tuesday
Unlocking AI with Model Context Protocol (MCP)
gpt5_lecture_notes_comprehensive_20250812015547.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
Mushroom cultivation and it's methods.pdf
Zenith AI: Advanced Artificial Intelligence
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Hindi spoken digit analysis for native and non-native speakers
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 5: Probability Theory and Statistics
Tartificialntelligence_presentation.pptx
TLE Review Electricity (Electricity).pptx
Ad

Presentation

  • 1. Erlang in a (real) nutshell Lu´ Ferreira ıs Universidade do Minho Semana da Lei II zamith.28@gmail.com July 13, 2010
  • 2. What is Erlang? Distributed Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 3. What is Erlang? Distributed Concurrent Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 4. What is Erlang? Distributed Concurrent Fault-tolerant Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 5. What is Erlang? Distributed Concurrent Fault-tolerant Functional based Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 6. Why use Erlang? NO Number-crunching applications Graphics intesive systems Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 7. Why use Erlang? NO Number-crunching applications Graphics intesive systems YES High-level, concurrent, robust, soft real-time system that will scale Make full use of multicore processors Integrate with components written in other languages Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 8. Some of the essential characteristics Low memory overhead per process/task Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 9. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 10. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 11. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 12. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Functional/single-assignment Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 13. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Functional/single-assignment Asynchronous message passing (send and pray) - Any Erlang value Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 14. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Functional/single-assignment Asynchronous message passing (send and pray) - Any Erlang value OS independent Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 15. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Functional/single-assignment Asynchronous message passing (send and pray) - Any Erlang value OS independent Messages retrieved selectively from the mailbox Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 16. Some of the essential characteristics Low memory overhead per process/task Thousands of processes - Own memory space, heap and stack No ”global” errors. Stop errors propagating Predictable performance Functional/single-assignment Asynchronous message passing (send and pray) - Any Erlang value OS independent Messages retrieved selectively from the mailbox Message passing by copy of data Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 17. Sequential Erlang Sort sort([Pivot|T]) -> sort([X||X <- T, X =< Pivot]) ++ [Pivot] ++ sort([X||X <- T, X >= Pivot]); sort([]) -> []. Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 18. Concurrent Erlang Area Server -module(server). -export([start/0]). start() -> register(server,spawn(fun() -> loop(0) end)). loop(Tot) -> receive {Pid, {square, X}} -> Pid ! X*X, loop(Tot + X*X); {Pid, {rectangle,[X,Y]}} -> Pid ! X*Y, loop(Tot + X*Y); {Pid, areas} -> Pid ! Tot, loop(Tot) end. Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 19. Concurrent Erlang Area Client -module(client). -export([square/1]). square(Val) -> server ! {self(),{square,Val}}, receive Area -> io:format("Area: ~p~n",[Val]) end. Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 20. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Exception handle Hot code replacement try return(X) when Generic behaviours is integer(X) -> ... try return error(X) of Val -> {normal,Val} catch exit:Reason -> {exit,Reason} throw:Throw -> {throw,Throw} error:Error -> {error,Error} end. Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 21. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Trap exits Hot code replacement process flag(trap exits, Generic behaviours true), ... P = spawn link(Node, Mod, Func, Args), receive {’EXIT’, P, Why}-> Actions; ... end Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 22. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Hot code replacement Generic behaviours ... worker supervisor Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 23. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Hot code replacement Generic behaviours ... Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 24. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Hot code replacement Generic behaviours ... Lu´ Ferreira ıs Erlang in a (real) nutshell
  • 25. Other features Fault tolerance (catch/throw) Trapping exits Linked processes Hot code replacement Generic behaviours ... Lu´ Ferreira ıs Erlang in a (real) nutshell