SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Erlang
    Message Passing
Concurrency, For The Win


            Toby DiPasquale
          Commerce360, Inc.
 Presented to Philly Linux Users Group
             June 6, 2007
Er-what?


                 Language/runtime created at Ericsson

                 Designed for scalable, long-lived systems

                 Not object oriented




Compiled, Functional, Dynamically typed, Open source
Another f*****
       language?

Pattern matching

Message-passing concurrency

Distributed programming

Hot code update
Runway Models

Meebo

SlideAware

RabbitMQ

Jabber.org

OpenPoker
Sequential
=

Not what you think it is, Performs a “binding”
Invokes pattern matching, Pattern matching like Prolog, nevermind Perl regexs
Syntax


                  Variables start with uppercase letter

                  Variables can only be assigned once

                  Last evaluation is return value of function




Functions and shell exprs end in period
Clauses end in semicolon
She’s got the look


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

square(X) ->
    X * X.
Atoms

                  Self-indicating identifiers

                  Start with lowercase letter

                  Can also be quoted with single quotes


                                      atom
                                this_is_an_atom
                              ‘I am also an atom’


Used just like you’d use an enum in C or a Symbol in Lisp or Ruby
Tuples
Fixed length containers

Often prepended with an identifier atom

Decompose with pattern matching

Car = {car,
        {honda, civic},
        {horsepower, 100}}.

{car, Type, Power} = Car.
Lists
                  Variable length containers

                  Use [H|T] syntax to get head and tail of
                  list

                 List = [1, 2, 3, four, 5.0]

                 [Head|Tail] = List

                 [H1,H2|T2] = List

Use lists just like you would in Lisp
Do something to head, recursively; [H|T] syntax is pattern matching
Strings
                  Not really

                  Strings are just lists of integers

                  Must use double quotes


                     Meeting = “PLUG”.

                     Meeting2 = [80,76,85,71].


Those two examples at the bottom are the same string; String handling blows in Erlang
No Unicode
Arity
 Use functions with same name and different
 arity* as auxiliary functions

-module(math_o_matics).
-export([sum/1]).

sum(L)        -> sum(L, 0).
sum([], N)    -> N;
sum([H|T], N) -> sum(T, H+N).

    * ‘Arity’ refers to the number of input parameters a function takes
Modules

                Logically associated code block

                Use colon (:) to use intermodule code

                Use -import to avoid prefixing



      io:format(“Using the module io~n”).


One module per file
The “fun” in functional

   Anonymous functions

   Used for higher-order programming



Square = fun(X) -> X * X end.

Cube = fun(X) -> Square(X) * X end.
List Comprehensions
    Takes an expression and a set of qualifiers
    and returns another list (like Python’s)

    Looks like: [X || Q1, Q2, ... Qn ]

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

                  Simple tests against a pattern matching

                  Can make code more concise



                   max(X, Y) when X > Y -> X;
                   max(X, Y) -> Y.


Multiple guards separated by a semicolon; Other guards include: arithmetic exprs, short-circuit boolean exprs,
constants (False), true (True)
Biting the bits


              Syntax for extracting/packing bits


               <<?IP_VERSION:4,
                  HLen:4, SrvcType:8, TotLen:16,
                  ID:16, Flgs:3, FragOff:13,
                  TTL:8, Proto:8, HdrChkSum:16,
                  SrcIP:32, DestIP:32, RestDgram/binary>>



Can do signed, unsigned, big-endian and little-endian, integer, float and binary qualifiers
Example decomposes an IPv4 packet
Concurrency
Shared Memory




                       Image credit: http://www.ja.org/nested/berrienandcass/kelly-vault.jpg


Lots of contention in there; Sweaty and noisy after a while
Unpleasant; Teacher must watch to make sure things go smoothly (single point of failure)
Message Passing




                       Image credit: http://english.people.com.cn/200512/21/images/pop2.jpg


Pass messages to communicate; Stability through replication and communication
More like real world concurrent systems; No mutexes, semaphores, monitors, etc to deal with
Processes


                 Basic unit of concurrency

                 Use spawn/0, !/1 (a.k.a. send) and
                 receive/1 BIF’s*

                 Asynchronous send, synchronous receive



                                       * BIF means “Built-in Function”


Owned by runtime, not OS; Very cheap and fast to spawn; No shared memory between processes
Concurrency Template*
                  -module(template).
                  -compile(export_all).

                  start() ->
                      spawn(fun() -> loop([]) end).

                  rpc(Pid, Query) ->
                      Pid ! {self(), Query},
                      receive
                           {Pid, Reply} ->
                               Reply
                      end.

                  loop(X) ->
                      receive
                           Any ->
                               io:format(quot;Received:~p~nquot;, [Any]),
                               loop(X)
                      end.
                         * Courtesy of Joe Armstrong in Programming Erlang, First Edition


loop/1 is tail-recursive
when you get a new message, add a clause to receive in rpc/2
Errors

                  Linking processes defines error chain

                  When a process dies, linked processes are
                  sent an exit signal

                  Use spawn_link/1 to spawn linked
                  processes




Only system processes can trap special exit signals
Distributing Erlang

                  Erlang has built-in support for distributed
                  operation

                  Two modes:

                       Distributed Erlang (easier, less secure)

                       Socket-based distribution (more secure)




Distributed Erlang looks largely the same as non-distributed
Distributing Erlang (2)

                  Two libraries for higher-level Distributed
                  Erlang:

                       rpc - RPC services

                       global - naming, locking, maintenance

                  Cookie based security model




security is crappy, suitable only for protected LANs
each machine is given a cookie; cookie must be same for all nodes in cluster
ets and dets


                  Erlang Term Storage (and Disk ets)

                  Dictionary for mad loads of Erlang data

                  ets tables are transient, dets are persistent




support insertion/lookup of keys and deletion of entire table
Mnesia

                  Real-time, distributed database that comes
                  with Erlang

                  Query language looks like SQL/list
                  comprehensions

                  Built-in visualization tools




Can store data in memory or on disk
Mnesia is built on top of ets and dets
OTP


                  Open Telecom Platform

                  Web server, FTP server, CORBA ORB, ASN.1,
                  SNMP, etc

                  Designed around encapsulated “behaviors”




Has lots more than telco stu; set of libraries and platforms for building large-scale apps
behaviors help code up large-scale apps (e.g. gen_tcp, gen_server)
Hot Erlang-on-Erlang
                        action
                  Yaws

                         Super scalable Web server/platform

                  ejabberd

                         Super scalable XMPP server

                  RabbitMQ

                         Super scalable message broker


Seeing a pattern here?
RTFM
Programming Erlang (PDF and dead tree
versions; great book)

Concurrent Programming with Erlang (older;
first half available online)

Erlang Website

Trapexit forums

erlang-questions mailing list
Huh huh huh huh... you said
         ‘Erlang’
  Slides: http://cbcg.net/talks/erlang.pdf

            Me: toby@cbcg.net

Más contenido relacionado

La actualidad más candente

Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and ExecutionChong-Kuan Chen
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Uglyenriquepazperez
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionCherryBerry2
 
Implementation - Sample Runs
Implementation - Sample RunsImplementation - Sample Runs
Implementation - Sample RunsAdwiteeya Agrawal
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friendAlexandre Moneger
 
OpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersOpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersDhanashree Prasad
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and ParallelizationDmitri Nesteruk
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelAlexey Smirnov
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open MpAnshul Sharma
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4Max Kleiner
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Adam Dunkels
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Max Kleiner
 

La actualidad más candente (20)

Open mp intro_01
Open mp intro_01Open mp intro_01
Open mp intro_01
 
Loader
LoaderLoader
Loader
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Ugly
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
 
Implementation - Sample Runs
Implementation - Sample RunsImplementation - Sample Runs
Implementation - Sample Runs
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
 
OpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersOpenMP Tutorial for Beginners
OpenMP Tutorial for Beginners
 
Dynamic Linker
Dynamic LinkerDynamic Linker
Dynamic Linker
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and Parallelization
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into Kernel
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open Mp
 
Design
DesignDesign
Design
 
An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1
 
Lecture8
Lecture8Lecture8
Lecture8
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
Matlab isim link
Matlab isim linkMatlab isim link
Matlab isim link
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
 

Destacado

Scalable Networking
Scalable NetworkingScalable Networking
Scalable Networkingl xf
 
NDC London 2014: Thinking Like an Erlanger
NDC London 2014: Thinking Like an ErlangerNDC London 2014: Thinking Like an Erlanger
NDC London 2014: Thinking Like an ErlangerTorben Hoffmann
 
1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionaisPMP
 
Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in PythonSarah Mount
 
Comparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms SoftwareComparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms Softwarel xf
 
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...Leinylson Fontinele
 
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
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
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
 
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
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabberl xf
 
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
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012Eonblast
 
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)

Scalable Networking
Scalable NetworkingScalable Networking
Scalable Networking
 
NDC London 2014: Thinking Like an Erlanger
NDC London 2014: Thinking Like an ErlangerNDC London 2014: Thinking Like an Erlanger
NDC London 2014: Thinking Like an Erlanger
 
1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais
 
Cassandra
CassandraCassandra
Cassandra
 
Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in Python
 
Comparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms SoftwareComparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms Software
 
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
 
Apostila de sistemas operacionais
Apostila de sistemas operacionaisApostila de sistemas operacionais
Apostila de sistemas operacionais
 
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
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
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
 
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
 
Clojure values
Clojure valuesClojure values
Clojure values
 
Elixir talk
Elixir talkElixir talk
Elixir talk
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
High Performance Erlang
High  Performance  ErlangHigh  Performance  Erlang
High Performance Erlang
 
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)
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
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 Erlang Message Passing Concurrency, For The Win

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
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrongSentifi
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 
Diving into Functional Programming
Diving into Functional ProgrammingDiving into Functional Programming
Diving into Functional ProgrammingLev Walkin
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environmentsJ'tong Atong
 
Лев Валкин — Программируем функционально
Лев Валкин — Программируем функциональноЛев Валкин — Программируем функционально
Лев Валкин — Программируем функциональноDaria Oreshkina
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational BiologyAtreyiB
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03duquoi
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with ErlangMaxim Kharchenko
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 

Similar a Erlang Message Passing Concurrency, For The Win (20)

Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
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...
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
Diving into Functional Programming
Diving into Functional ProgrammingDiving into Functional Programming
Diving into Functional Programming
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Лев Валкин — Программируем функционально
Лев Валкин — Программируем функциональноЛев Валкин — Программируем функционально
Лев Валкин — Программируем функционально
 
Elixir introduction
Elixir introductionElixir introduction
Elixir introduction
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Erlang session1
Erlang session1Erlang session1
Erlang session1
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Erlang OTP
Erlang OTPErlang OTP
Erlang OTP
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 

Más de l xf

Asynchronous Io Programming
Asynchronous Io ProgrammingAsynchronous Io Programming
Asynchronous Io Programmingl xf
 
The Proactor Pattern
The Proactor PatternThe Proactor Pattern
The Proactor Patternl xf
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Evel xf
 
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...l xf
 
Concurrency And Erlang
Concurrency And ErlangConcurrency And Erlang
Concurrency And Erlangl xf
 
Learning Erlang And Developing A Sip Server Stack With 30k Potential Users
Learning Erlang And Developing A Sip Server Stack With 30k Potential UsersLearning Erlang And Developing A Sip Server Stack With 30k Potential Users
Learning Erlang And Developing A Sip Server Stack With 30k Potential Usersl xf
 
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...l xf
 

Más de l xf (7)

Asynchronous Io Programming
Asynchronous Io ProgrammingAsynchronous Io Programming
Asynchronous Io Programming
 
The Proactor Pattern
The Proactor PatternThe Proactor Pattern
The Proactor Pattern
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...The Migration From Erlang To Otp   A Case Study Of A Heavy Duty Tcpip Clients...
The Migration From Erlang To Otp A Case Study Of A Heavy Duty Tcpip Clients...
 
Concurrency And Erlang
Concurrency And ErlangConcurrency And Erlang
Concurrency And Erlang
 
Learning Erlang And Developing A Sip Server Stack With 30k Potential Users
Learning Erlang And Developing A Sip Server Stack With 30k Potential UsersLearning Erlang And Developing A Sip Server Stack With 30k Potential Users
Learning Erlang And Developing A Sip Server Stack With 30k Potential Users
 
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...
A Virtual World Distributed Server Developed In Erlang As A Tool For Analysin...
 

Último

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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
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
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
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
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Último (20)

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...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
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...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
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
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

Erlang Message Passing Concurrency, For The Win

  • 1. Erlang Message Passing Concurrency, For The Win Toby DiPasquale Commerce360, Inc. Presented to Philly Linux Users Group June 6, 2007
  • 2. Er-what? Language/runtime created at Ericsson Designed for scalable, long-lived systems Not object oriented Compiled, Functional, Dynamically typed, Open source
  • 3. Another f***** language? Pattern matching Message-passing concurrency Distributed programming Hot code update
  • 6. = Not what you think it is, Performs a “binding” Invokes pattern matching, Pattern matching like Prolog, nevermind Perl regexs
  • 7. Syntax Variables start with uppercase letter Variables can only be assigned once Last evaluation is return value of function Functions and shell exprs end in period Clauses end in semicolon
  • 8. She’s got the look -module(math_o_matics). -export([square/1]). square(X) -> X * X.
  • 9. Atoms Self-indicating identifiers Start with lowercase letter Can also be quoted with single quotes atom this_is_an_atom ‘I am also an atom’ Used just like you’d use an enum in C or a Symbol in Lisp or Ruby
  • 10. Tuples Fixed length containers Often prepended with an identifier atom Decompose with pattern matching Car = {car, {honda, civic}, {horsepower, 100}}. {car, Type, Power} = Car.
  • 11. Lists Variable length containers Use [H|T] syntax to get head and tail of list List = [1, 2, 3, four, 5.0] [Head|Tail] = List [H1,H2|T2] = List Use lists just like you would in Lisp Do something to head, recursively; [H|T] syntax is pattern matching
  • 12. Strings Not really Strings are just lists of integers Must use double quotes Meeting = “PLUG”. Meeting2 = [80,76,85,71]. Those two examples at the bottom are the same string; String handling blows in Erlang No Unicode
  • 13. Arity Use functions with same name and different arity* as auxiliary functions -module(math_o_matics). -export([sum/1]). sum(L) -> sum(L, 0). sum([], N) -> N; sum([H|T], N) -> sum(T, H+N). * ‘Arity’ refers to the number of input parameters a function takes
  • 14. Modules Logically associated code block Use colon (:) to use intermodule code Use -import to avoid prefixing io:format(“Using the module io~n”). One module per file
  • 15. The “fun” in functional Anonymous functions Used for higher-order programming Square = fun(X) -> X * X end. Cube = fun(X) -> Square(X) * X end.
  • 16. List Comprehensions Takes an expression and a set of qualifiers and returns another list (like Python’s) Looks like: [X || Q1, Q2, ... Qn ] qsort([]) -> []; qsort([Pivot|T]) -> qsort([X || X <- T, X < Pivot]) ++ [Pivot] ++ qsort([X || X <- T, X >= Pivot]).
  • 17. Guards Simple tests against a pattern matching Can make code more concise max(X, Y) when X > Y -> X; max(X, Y) -> Y. Multiple guards separated by a semicolon; Other guards include: arithmetic exprs, short-circuit boolean exprs, constants (False), true (True)
  • 18. Biting the bits Syntax for extracting/packing bits <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, ID:16, Flgs:3, FragOff:13, TTL:8, Proto:8, HdrChkSum:16, SrcIP:32, DestIP:32, RestDgram/binary>> Can do signed, unsigned, big-endian and little-endian, integer, float and binary qualifiers Example decomposes an IPv4 packet
  • 20. Shared Memory Image credit: http://www.ja.org/nested/berrienandcass/kelly-vault.jpg Lots of contention in there; Sweaty and noisy after a while Unpleasant; Teacher must watch to make sure things go smoothly (single point of failure)
  • 21. Message Passing Image credit: http://english.people.com.cn/200512/21/images/pop2.jpg Pass messages to communicate; Stability through replication and communication More like real world concurrent systems; No mutexes, semaphores, monitors, etc to deal with
  • 22. Processes Basic unit of concurrency Use spawn/0, !/1 (a.k.a. send) and receive/1 BIF’s* Asynchronous send, synchronous receive * BIF means “Built-in Function” Owned by runtime, not OS; Very cheap and fast to spawn; No shared memory between processes
  • 23. Concurrency Template* -module(template). -compile(export_all). start() -> spawn(fun() -> loop([]) end). rpc(Pid, Query) -> Pid ! {self(), Query}, receive {Pid, Reply} -> Reply end. loop(X) -> receive Any -> io:format(quot;Received:~p~nquot;, [Any]), loop(X) end. * Courtesy of Joe Armstrong in Programming Erlang, First Edition loop/1 is tail-recursive when you get a new message, add a clause to receive in rpc/2
  • 24. Errors Linking processes defines error chain When a process dies, linked processes are sent an exit signal Use spawn_link/1 to spawn linked processes Only system processes can trap special exit signals
  • 25. Distributing Erlang Erlang has built-in support for distributed operation Two modes: Distributed Erlang (easier, less secure) Socket-based distribution (more secure) Distributed Erlang looks largely the same as non-distributed
  • 26. Distributing Erlang (2) Two libraries for higher-level Distributed Erlang: rpc - RPC services global - naming, locking, maintenance Cookie based security model security is crappy, suitable only for protected LANs each machine is given a cookie; cookie must be same for all nodes in cluster
  • 27. ets and dets Erlang Term Storage (and Disk ets) Dictionary for mad loads of Erlang data ets tables are transient, dets are persistent support insertion/lookup of keys and deletion of entire table
  • 28. Mnesia Real-time, distributed database that comes with Erlang Query language looks like SQL/list comprehensions Built-in visualization tools Can store data in memory or on disk Mnesia is built on top of ets and dets
  • 29. OTP Open Telecom Platform Web server, FTP server, CORBA ORB, ASN.1, SNMP, etc Designed around encapsulated “behaviors” Has lots more than telco stu; set of libraries and platforms for building large-scale apps behaviors help code up large-scale apps (e.g. gen_tcp, gen_server)
  • 30. Hot Erlang-on-Erlang action Yaws Super scalable Web server/platform ejabberd Super scalable XMPP server RabbitMQ Super scalable message broker Seeing a pattern here?
  • 31. RTFM Programming Erlang (PDF and dead tree versions; great book) Concurrent Programming with Erlang (older; first half available online) Erlang Website Trapexit forums erlang-questions mailing list
  • 32. Huh huh huh huh... you said ‘Erlang’ Slides: http://cbcg.net/talks/erlang.pdf Me: toby@cbcg.net