SlideShare a Scribd company logo
1 of 73
An introduction to Erlang




     Code Lovers 30-1-2012

           @MirkoBonadei
Our Agenda
- Introduction

- Some bits of history

- The Erlang Way

- Inside the VM

- OTP (Open Telecom Platform)

- Who uses it?

- Conclusion
Erlang is about processes

                     P3


                                            P5
 P2


                               P1

              P4




They are the basic components to model a system.
Process isolation



Chrome                        Word




         An O.S. Example...
Process isolation



    Chrome                        Word




Your favourite word processor crashes but your
            browser is still running
Erlang Processes




Processes are cheap and lightweight.
   We can have millions of them.
Context Switch and IPC are really fast.
Some bits of History



Erlang came to the masses
    in 2006/07 but....
Some bits of History



Erlang is 25 years old!
So... Why 20 years of silence?
What's happened


  Distributed Systems


       Multicore


Technology “penetration”
Crystal Ball?!?
Nope, Industrial Requests

                          Ericsson was looking for a
                          language to replace PLEX
                              (their development
                             language in the 80s)


                        Requests:

                                    Distributed          Declarative
Time to Market

                     Hot Code Swapping
   Fault Tolerant
                    Soft Realtime                 Concurrent
Research is the key
At the Ericsson Lab they developed some pilot projects in various
programming languages...


                                               Chill
         ML             Miranda


                                                         Others...
                                     SmallT
                                      alk
                   Prolog
   Ada
But

There wasn't a language with all those features




                               Let's create our
                                  language!
Good results!


The first version was a language implemented
              on the top of Prolog.

After some good results, they wrote the JAM
Machine in C, boosting performance of 70%.

We are in the early 90s, and the “Erlang Era”
               has just began.
But...
After lots of great results, Ericsson banned
   Erlang from future projects in 1998.
    They chose to follow competitors...



 Ericsson released Erlang as Open Source




    Core developers left Ericsson and
        founded their companies
Ericsson comes back

Understanding the error made, they come back
                 to Erlang.



   Ericsson re-hired Joe Armstrong in 2004



   The OTP Team is now based in Ericsson.
Let's start....



talking about
 concurrency
Concurrency we are used to...
                         Error Handling
                              code
Coordination
   code




 Code to solve the
     problem
What this means?

Loosing Abstraction


Complexity explodes


Maintenance is hard
The Erlang Way




The best way to understand the Erlang way is to
            think at the real world.
              World is concurrent,
        this is the abstraction we want.
It is simple


To obtain scalability and fault tolerance is quite
 easy. You took 2 things, you make them share
nothing and you get fault tolerance and you can
                      scale.


              Joe Armstrong (London Erlang Factory 2011)
Type System


Erlang is dynamically typed

            &

 Erlang is strongly typed
Type: Number
Type: Atom
Type: Binary and Bit String



Bit Syntax and Pattern Matching:
Type: Pid
Type: Port Identifier

            Basic mechanism
             to communicate
        with a non Erlang program


The Port Identifier is returned by the call to
           the BIF open_port/2
Type: Tuple
Type: List
Type: Fun




Ehy... Erlang is a Functional language :)
Type: Reference




   A term which is unique
in an Erlang Runtime System
No Type: String




A String is simply a list of integer values
No Type: Boolean




true and false are nothing than atoms
No Type: Record
Pattern Matching 1/3




 Referential Transparency
Pattern Matching 2/3
Pattern Matching 3/3


         Ehy, we've got some recursion here!
“Don't Care” Variables




Really useful, but use them with care
Processes and IPC

To create a process we use the spawn functions.
  There are different versions of spawn, for all
             the possible scenarios.


    Every Process has its “MailBox” where
          its messages are delivered.


To send a message to a process we use a one
           character operator, !
An Example
An Example
An Example
How to deal with Errors

Erlang has an Exception system with 3 classes of
errors:

- error: It is a runtime error or it could be
         generated from the call error(Reason)

- exit: generated from the code with the call
        exit(Reason)

- throw: generated from the code with the call
         throw(Reason)
Try … Catch




But Between Processes...
Exit Signals
        When a process terminates it emits
        (with its last breath) an exit signal
         with the reason of its termination


              The reason could be normal
      if things are terminated it the right way,
             or it could be something else,
    and in this case the termination is abnormal.


 We can use processes to isolate errors, make that
part of the system fail fast, and eventually restart it.
Links

                 {'EXIT', Pid2, Reason}

     P1                                   P2




We can link processes together with link/1 BIF or
          directly with spawn_link BIFs.


 Linked processes forms a linked set, and if one of
them terminates abnormally, the error propagates
    the the linked set, taking processes down.
Trapping Exits

                  {'EXIT', Pid2, Reason}

    P1                                     P2




 We can trap exits, making a process become a
             system process with:
        process_flag(trap_exits, true).

 Now it receives the message, and it can choose
what to do. Stopping the propagation of the error.

         Only the Reason kill is untrappable!
Robustness

                S




    S          W           W




                    S → Supervisor
W       W            W → Worker
Monitors




      While links are bidirectional,
      monitors are unidirectional.
No link set, the monitor process is like a
                “stalker”.
Distribution




Distribution is built into
  the language itself.
Are you kidding?

       Nope, think about it...


        No shared memory.
So, we copy data between processes
       on the same machine.
               And...
 We copy data between processes
       on different machines.
Ok, and the location?



  ! operator is location transparent

A Pid also contains information on the
        location of the process.
Erlang Clusters



It is really simple to create
      an Erlang cluster.

There are apposite libraries,
 and when a cluster is set,
you work without headache.
Hot Code Swapping


      No Downtime allowed
       for bad guys like us!

               So...

Hot Code Swapping is built into the
         language itself!
How does it woks?
Instant 0
                P




            -vsn(1.0)
How does it woks?
Instant 1
                        P




            -vsn(1.0)       -vsn(1.1)
How does it woks?
Instant 2
                        P




            -vsn(1.0)       -vsn(1.1)
How does it woks?
Instant 3
                P




 -vsn(1.0)   -vsn(1.1)   -vsn(1.2)
Warning!
Code upgrades on intra-module function
           calls could bite you.
      The function calls must be
      fully qualified calls such as:


<module_name> : <function_name>(<args,....>)



If you follow OTP Principles you can get
           Hot Code Swapping
    the right way “without” headache
Warning!


Hot Code Swapping is a difficult task

     Even if Erlang helps you...

     Test Hard your solutions
  before taking the system down.
ERTS and the VM

    No clear separation between
            ERTS and VM.


 VM runs compiled byte-code (BEAM)

ERTS manages Processes, IPC, Memory,
       Load Balancing, ecc...

     We always call VM both two!
The Scheduler


      Fundamental part of the
      Erlang Runtime System.


It has been deeply changed during the
last years to rule multi-core hardware
             the right way
In the past
  The scheduler was there to manage
execution of Erlang processes inside an
   O.S. Process called beam or werl

                            Run Queue



Scheduler
Then...
     Symmetric Multiprocessing was
        released in May 2006


Scheduler #1               Run Queue



Scheduler #..



Scheduler #N
Today
           Bottleneck removed.
        One run queue for scheduler.

Scheduler   RQ
   #1


Scheduler   RQ
   #...                          Migration
                                   Logic

Scheduler   RQ
   #N
Garbage Collection

      Per process Garbage Collection


         Small processes means
         quick garbage collection


Garbage Collection doesn't pause the system
      as happens in other languages.
  Soft Real-time feature is safe even with
        million of processes running
OTP: Open Telecom Platform

Set of tools, libraries and design principles to
       develop distributed applications


 Do not reinvent the wheel every time, use
          OTP behaviours instead!


   Supervisor trees, Hot Code Swapping,
       Packaging, abstracted away
OTP Benefits
Less code to write means, less bug and fast
              time to market


  Easy to test your specific functionality


Common coding style between developers


           OTP is battle tested
Who uses Erlang
Who uses Erlang




And many others...
Books




learnyousomeerlang.com
Next Conferences
Thanks

More Related Content

What's hot

Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrongSentifi
 
Why functional programming in C# & F#
Why functional programming in C# & F#Why functional programming in C# & F#
Why functional programming in C# & F#Riccardo Terrell
 
OTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleOTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleYangJerng Hwa
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)Dierk König
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming LanguageReham AlBlehid
 
FregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMFregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMDierk König
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsElixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsBenjamin Tan
 
Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammenReidar Sollid
 
MERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingMERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingOlivier NAVARRE
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQpieterh
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQpieterh
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...Gianluca Padovani
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with XtendSven Efftinge
 

What's hot (20)

Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
Why functional programming in C# & F#
Why functional programming in C# & F#Why functional programming in C# & F#
Why functional programming in C# & F#
 
Ia+ threading
Ia+ threadingIa+ threading
Ia+ threading
 
OTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleOTP application (with gen server child) - simple example
OTP application (with gen server child) - simple example
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming Language
 
FregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMFregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVM
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsElixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
 
Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammen
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
MERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingMERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel Programming
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQ
 
Fork Join
Fork JoinFork Join
Fork Join
 
Elixir otp-basics
Elixir otp-basicsElixir otp-basics
Elixir otp-basics
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQ
 
Elixir
ElixirElixir
Elixir
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
OIVM
OIVMOIVM
OIVM
 

Viewers also liked

Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlangasceth
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practicelitaocheng
 
learn you some erlang - chap 9 to chap10
learn you some erlang - chap 9 to chap10learn you some erlang - chap 9 to chap10
learn you some erlang - chap 9 to chap10경미 김
 
Getting real with erlang
Getting real with erlangGetting real with erlang
Getting real with erlangPaolo Negri
 
Erlang Concurrency
Erlang ConcurrencyErlang Concurrency
Erlang ConcurrencyBarry Ezell
 
Lightning Talk: Erlang on Xen - Mikhail Bortnyk
Lightning Talk: Erlang on Xen - Mikhail BortnykLightning Talk: Erlang on Xen - Mikhail Bortnyk
Lightning Talk: Erlang on Xen - Mikhail BortnykElixir Club
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabberl xf
 
20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)Pavlo Baron
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Winning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleWinning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleRusty Klophaus
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaErlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaHakka Labs
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012Eonblast
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Howard Lewis Ship
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsTorben Hoffmann
 

Viewers also liked (20)

Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practice
 
learn you some erlang - chap 9 to chap10
learn you some erlang - chap 9 to chap10learn you some erlang - chap 9 to chap10
learn you some erlang - chap 9 to chap10
 
Getting real with erlang
Getting real with erlangGetting real with erlang
Getting real with erlang
 
Erlang Concurrency
Erlang ConcurrencyErlang Concurrency
Erlang Concurrency
 
Lightning Talk: Erlang on Xen - Mikhail Bortnyk
Lightning Talk: Erlang on Xen - Mikhail BortnykLightning Talk: Erlang on Xen - Mikhail Bortnyk
Lightning Talk: Erlang on Xen - Mikhail Bortnyk
 
Clojure values
Clojure valuesClojure values
Clojure values
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)
 
Clojure class
Clojure classClojure class
Clojure class
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
High Performance Erlang
High  Performance  ErlangHigh  Performance  Erlang
High Performance Erlang
 
Elixir talk
Elixir talkElixir talk
Elixir talk
 
Winning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleWinning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test Cycle
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaErlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 

Similar to An introduction to erlang

Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsSentifi
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...siouxhotornot
 
Erlang
ErlangErlang
ErlangESUG
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futureTakayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexingMark Veltzer
 
Why Erlang? - Bar Camp Atlanta 2008
Why Erlang?  - Bar Camp Atlanta 2008Why Erlang?  - Bar Camp Atlanta 2008
Why Erlang? - Bar Camp Atlanta 2008boorad
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus44CON
 
Erlang及其应用
Erlang及其应用Erlang及其应用
Erlang及其应用Feng Yu
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionAndré Graf
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_nealeMichael Neale
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 
Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)Gianluca Padovani
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeDmitri Nesteruk
 

Similar to An introduction to erlang (20)

Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
 
Erlang
ErlangErlang
Erlang
 
Erlang os
Erlang osErlang os
Erlang os
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexing
 
Why Erlang? - Bar Camp Atlanta 2008
Why Erlang?  - Bar Camp Atlanta 2008Why Erlang?  - Bar Camp Atlanta 2008
Why Erlang? - Bar Camp Atlanta 2008
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
 
Erlang及其应用
Erlang及其应用Erlang及其应用
Erlang及其应用
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Erlang in 10 minutes
Erlang in 10 minutesErlang in 10 minutes
Erlang in 10 minutes
 
Beam me up, Scotty
Beam me up, ScottyBeam me up, Scotty
Beam me up, Scotty
 
Elixir
ElixirElixir
Elixir
 
Erlang real time
Erlang real timeErlang real time
Erlang real time
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

An introduction to erlang

  • 1. An introduction to Erlang Code Lovers 30-1-2012 @MirkoBonadei
  • 2. Our Agenda - Introduction - Some bits of history - The Erlang Way - Inside the VM - OTP (Open Telecom Platform) - Who uses it? - Conclusion
  • 3. Erlang is about processes P3 P5 P2 P1 P4 They are the basic components to model a system.
  • 4. Process isolation Chrome Word An O.S. Example...
  • 5. Process isolation Chrome Word Your favourite word processor crashes but your browser is still running
  • 6. Erlang Processes Processes are cheap and lightweight. We can have millions of them. Context Switch and IPC are really fast.
  • 7. Some bits of History Erlang came to the masses in 2006/07 but....
  • 8. Some bits of History Erlang is 25 years old! So... Why 20 years of silence?
  • 9. What's happened Distributed Systems Multicore Technology “penetration”
  • 11. Nope, Industrial Requests Ericsson was looking for a language to replace PLEX (their development language in the 80s) Requests: Distributed Declarative Time to Market Hot Code Swapping Fault Tolerant Soft Realtime Concurrent
  • 12. Research is the key At the Ericsson Lab they developed some pilot projects in various programming languages... Chill ML Miranda Others... SmallT alk Prolog Ada
  • 13. But There wasn't a language with all those features Let's create our language!
  • 14. Good results! The first version was a language implemented on the top of Prolog. After some good results, they wrote the JAM Machine in C, boosting performance of 70%. We are in the early 90s, and the “Erlang Era” has just began.
  • 15. But... After lots of great results, Ericsson banned Erlang from future projects in 1998. They chose to follow competitors... Ericsson released Erlang as Open Source Core developers left Ericsson and founded their companies
  • 16. Ericsson comes back Understanding the error made, they come back to Erlang. Ericsson re-hired Joe Armstrong in 2004 The OTP Team is now based in Ericsson.
  • 18. Concurrency we are used to... Error Handling code Coordination code Code to solve the problem
  • 19. What this means? Loosing Abstraction Complexity explodes Maintenance is hard
  • 20. The Erlang Way The best way to understand the Erlang way is to think at the real world. World is concurrent, this is the abstraction we want.
  • 21. It is simple To obtain scalability and fault tolerance is quite easy. You took 2 things, you make them share nothing and you get fault tolerance and you can scale. Joe Armstrong (London Erlang Factory 2011)
  • 22. Type System Erlang is dynamically typed & Erlang is strongly typed
  • 25. Type: Binary and Bit String Bit Syntax and Pattern Matching:
  • 27. Type: Port Identifier Basic mechanism to communicate with a non Erlang program The Port Identifier is returned by the call to the BIF open_port/2
  • 30. Type: Fun Ehy... Erlang is a Functional language :)
  • 31. Type: Reference A term which is unique in an Erlang Runtime System
  • 32. No Type: String A String is simply a list of integer values
  • 33. No Type: Boolean true and false are nothing than atoms
  • 35. Pattern Matching 1/3 Referential Transparency
  • 37. Pattern Matching 3/3 Ehy, we've got some recursion here!
  • 38. “Don't Care” Variables Really useful, but use them with care
  • 39. Processes and IPC To create a process we use the spawn functions. There are different versions of spawn, for all the possible scenarios. Every Process has its “MailBox” where its messages are delivered. To send a message to a process we use a one character operator, !
  • 43. How to deal with Errors Erlang has an Exception system with 3 classes of errors: - error: It is a runtime error or it could be generated from the call error(Reason) - exit: generated from the code with the call exit(Reason) - throw: generated from the code with the call throw(Reason)
  • 44. Try … Catch But Between Processes...
  • 45. Exit Signals When a process terminates it emits (with its last breath) an exit signal with the reason of its termination The reason could be normal if things are terminated it the right way, or it could be something else, and in this case the termination is abnormal. We can use processes to isolate errors, make that part of the system fail fast, and eventually restart it.
  • 46. Links {'EXIT', Pid2, Reason} P1 P2 We can link processes together with link/1 BIF or directly with spawn_link BIFs. Linked processes forms a linked set, and if one of them terminates abnormally, the error propagates the the linked set, taking processes down.
  • 47. Trapping Exits {'EXIT', Pid2, Reason} P1 P2 We can trap exits, making a process become a system process with: process_flag(trap_exits, true). Now it receives the message, and it can choose what to do. Stopping the propagation of the error. Only the Reason kill is untrappable!
  • 48. Robustness S S W W S → Supervisor W W W → Worker
  • 49. Monitors While links are bidirectional, monitors are unidirectional. No link set, the monitor process is like a “stalker”.
  • 50. Distribution Distribution is built into the language itself.
  • 51. Are you kidding? Nope, think about it... No shared memory. So, we copy data between processes on the same machine. And... We copy data between processes on different machines.
  • 52. Ok, and the location? ! operator is location transparent A Pid also contains information on the location of the process.
  • 53. Erlang Clusters It is really simple to create an Erlang cluster. There are apposite libraries, and when a cluster is set, you work without headache.
  • 54. Hot Code Swapping No Downtime allowed for bad guys like us! So... Hot Code Swapping is built into the language itself!
  • 55. How does it woks? Instant 0 P -vsn(1.0)
  • 56. How does it woks? Instant 1 P -vsn(1.0) -vsn(1.1)
  • 57. How does it woks? Instant 2 P -vsn(1.0) -vsn(1.1)
  • 58. How does it woks? Instant 3 P -vsn(1.0) -vsn(1.1) -vsn(1.2)
  • 59. Warning! Code upgrades on intra-module function calls could bite you. The function calls must be fully qualified calls such as: <module_name> : <function_name>(<args,....>) If you follow OTP Principles you can get Hot Code Swapping the right way “without” headache
  • 60. Warning! Hot Code Swapping is a difficult task Even if Erlang helps you... Test Hard your solutions before taking the system down.
  • 61. ERTS and the VM No clear separation between ERTS and VM. VM runs compiled byte-code (BEAM) ERTS manages Processes, IPC, Memory, Load Balancing, ecc... We always call VM both two!
  • 62. The Scheduler Fundamental part of the Erlang Runtime System. It has been deeply changed during the last years to rule multi-core hardware the right way
  • 63. In the past The scheduler was there to manage execution of Erlang processes inside an O.S. Process called beam or werl Run Queue Scheduler
  • 64. Then... Symmetric Multiprocessing was released in May 2006 Scheduler #1 Run Queue Scheduler #.. Scheduler #N
  • 65. Today Bottleneck removed. One run queue for scheduler. Scheduler RQ #1 Scheduler RQ #... Migration Logic Scheduler RQ #N
  • 66. Garbage Collection Per process Garbage Collection Small processes means quick garbage collection Garbage Collection doesn't pause the system as happens in other languages. Soft Real-time feature is safe even with million of processes running
  • 67. OTP: Open Telecom Platform Set of tools, libraries and design principles to develop distributed applications Do not reinvent the wheel every time, use OTP behaviours instead! Supervisor trees, Hot Code Swapping, Packaging, abstracted away
  • 68. OTP Benefits Less code to write means, less bug and fast time to market Easy to test your specific functionality Common coding style between developers OTP is battle tested
  • 70. Who uses Erlang And many others...