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

Similar to Presentation

Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 
Webinar: Live without Exception in Rust
Webinar: Live without Exception in RustWebinar: Live without Exception in Rust
Webinar: Live without Exception in Rust
Knoldus Inc.
 
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
PROIDEA
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
Jordan Parmer
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
Sentifi
 
You shall not get excited
You shall not get excitedYou shall not get excited
You shall not get excited
x697272
 

Similar to Presentation (7)

Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
Webinar: Live without Exception in Rust
Webinar: Live without Exception in RustWebinar: Live without Exception in Rust
Webinar: Live without Exception in Rust
 
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski4Developers 2015: Lessons for Erlang VM - Michał Ślaski
4Developers 2015: Lessons for Erlang VM - Michał Ślaski
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
 
Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
 
You shall not get excited
You shall not get excitedYou shall not get excited
You shall not get excited
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

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