SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
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
 
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 a 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
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
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
 
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
 
Elixir
ElixirElixir
Elixir
 
Beam me up, Scotty
Beam me up, ScottyBeam me up, Scotty
Beam me up, Scotty
 
Erlang real time
Erlang real timeErlang real time
Erlang real time
 

Último

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 

Último (20)

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 

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...