Erlang FTW!
  {   Mahesh Paolini-Subramanya (@dieswaytoofast)
      V.P. Ubiquiti Networks
      James Aimonetti (@jamesaimonetti)
Erlang Everywhere
Why Erlang?
   Horizontal




Scalability
   Horizontal




Scalability
   Horizontal

        Vertical




Scalability
   Horizontal

        Vertical




Scalability
   Live!




Hot Swapping
   Live!




Hot Swapping
Asynchronous Processing
Asynchronous Processing
Asynchronous Processing
Supervision
Live Debugging
Stack Traces
Predictability
Why Erlang?
4x – 10x less code
   Faster to create




4x – 10x less code
   Faster to create

        Easier to reason about




4x – 10x less code
   Faster to create

        Easier to reason about

        Fewer bugs




4x – 10x less code
   Faster to create

        Easier to reason about

        Fewer bugs

        Speedy refactoring




4x – 10x less code
vs



Scalability
Speed
Reliability
   Concurrency by default
       Error encapsulation
       Fault detection
       Fault identification
       Code upgrade
       Stable Storage

                    From http://www.erlang.org/download/armstrong_thesis_2003.pdf




Concurrency Oriented
My Blue Heaven     My Blue Heaven



Concurrency Hell




Concurrency Oriented
My Blue Heaven     My Blue Heaven



 Deep Problem s



 Concurrency Hell

                    Deep Problem s


Concurrency Oriented
Cheap Actors
   Shared vs shared-nothing




OO vs Actors
   Shared vs shared-nothing

       Inheritance vs Behavior




OO vs Actors
   Shared vs shared-nothing

       Inheritance vs Behavior

       Sync vs Async




OO vs Actors
Why Not Java? (Ruby/…)
Why not assembler?
   Trivial thread management (hint: none)




Erlang Architecture
   Trivial thread management (hint: none)

       Trivial monitoring / load-balancing




Erlang Architecture
   Trivial thread management (hint: none)

       Trivial monitoring / load-balancing

       One process per session




Erlang Architecture
 X = 1.




Immutable Variables
 X = 1.

     X = 2.




               Huh?
Immutable Variables
 X = 1.

     X = 2.

     X = X + 1.




                   Huh?
Immutable Variables
 [ do_something_with(X) || X <- ListOfItems ]




List Comprehensions
function greet( Gender, Name )
  if Gender == male then
     print( "Hello, Mr. %s!", Name )
  else if Gender == female then
     print( "Hello, Mrs. %s!", Name )
  else
     print( "Hello, %s!", Name )
end



                      vs                greet( male, Name ) ->
                                          print_out( “Hello Mr. ”, Name );
                                        greet( female, Name ) ->
                                          print_out( “Greetings Mrs. ”, Name );
                                        greet( _, Name ) ->
                                          print_out( “Wotcher ”, Name ).


 Functions                               From http://learnyousomeerlang.com/
Module:code_change( OldVersion, OldState, Stuff ) ->

    NewState = whatever_you_need_to_do( OldVersion, OldState, Stuff ),

    { ok, NewState }.



                             vs
Monkey Patching?

Really?

You sure?


Functions
<< Header:16, Checksum:4, Payload/binary >>.




Bit Syntax
[ process_payload(Payload) ||
     <<_Header:16, _Checksum:4, Payload/binary>>
         <= BunchOfData ].




Binary Comprehensions!
…
  proc:spawn( fun( X ) -> do_stuff( X ) end ),
  …

  do_stuff( OnePerson ) -> change_the_world( OnePerson ).




Processes
if ( X instanceof Integer ) {
   try {
      change_position( X );
   } catch ( ArithmeticException a ) {
      // can't happen. ignore
   } catch ( PositionException p ) {
      // why would this happen?
   } catch ( Exception e ) {
      // The other code has this here
   } catch ( Throwable t ) {
      // Dunno why this was in the other code


                                                                 vs
    }
}




                         proc:spawn( fun( X ) -> change_position( X ) end ),

     Defensive Programming
   mahesh#dieswaytoofast.com / @dieswaytoofast

       james#2600hz.com / @jamesaimonetti




Questions

Erlang FTW!

  • 1.
    Erlang FTW! { Mahesh Paolini-Subramanya (@dieswaytoofast) V.P. Ubiquiti Networks James Aimonetti (@jamesaimonetti)
  • 2.
  • 3.
  • 4.
    Horizontal Scalability
  • 5.
    Horizontal Scalability
  • 6.
    Horizontal  Vertical Scalability
  • 7.
    Horizontal  Vertical Scalability
  • 8.
    Live! Hot Swapping
  • 9.
    Live! Hot Swapping
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
    4x – 10xless code
  • 19.
    Faster to create 4x – 10x less code
  • 20.
    Faster to create  Easier to reason about 4x – 10x less code
  • 21.
    Faster to create  Easier to reason about  Fewer bugs 4x – 10x less code
  • 22.
    Faster to create  Easier to reason about  Fewer bugs  Speedy refactoring 4x – 10x less code
  • 23.
  • 24.
  • 25.
  • 26.
    Concurrency by default  Error encapsulation  Fault detection  Fault identification  Code upgrade  Stable Storage From http://www.erlang.org/download/armstrong_thesis_2003.pdf Concurrency Oriented
  • 27.
    My Blue Heaven My Blue Heaven Concurrency Hell Concurrency Oriented
  • 28.
    My Blue Heaven My Blue Heaven Deep Problem s Concurrency Hell Deep Problem s Concurrency Oriented
  • 29.
  • 30.
    Shared vs shared-nothing OO vs Actors
  • 31.
    Shared vs shared-nothing  Inheritance vs Behavior OO vs Actors
  • 32.
    Shared vs shared-nothing  Inheritance vs Behavior  Sync vs Async OO vs Actors
  • 33.
    Why Not Java?(Ruby/…)
  • 34.
  • 36.
    Trivial thread management (hint: none) Erlang Architecture
  • 37.
    Trivial thread management (hint: none)  Trivial monitoring / load-balancing Erlang Architecture
  • 38.
    Trivial thread management (hint: none)  Trivial monitoring / load-balancing  One process per session Erlang Architecture
  • 39.
     X =1. Immutable Variables
  • 40.
     X =1.  X = 2. Huh? Immutable Variables
  • 41.
     X =1.  X = 2.  X = X + 1. Huh? Immutable Variables
  • 42.
     [ do_something_with(X)|| X <- ListOfItems ] List Comprehensions
  • 43.
    function greet( Gender,Name ) if Gender == male then print( "Hello, Mr. %s!", Name ) else if Gender == female then print( "Hello, Mrs. %s!", Name ) else print( "Hello, %s!", Name ) end vs greet( male, Name ) -> print_out( “Hello Mr. ”, Name ); greet( female, Name ) -> print_out( “Greetings Mrs. ”, Name ); greet( _, Name ) -> print_out( “Wotcher ”, Name ). Functions From http://learnyousomeerlang.com/
  • 44.
    Module:code_change( OldVersion, OldState,Stuff ) -> NewState = whatever_you_need_to_do( OldVersion, OldState, Stuff ), { ok, NewState }. vs Monkey Patching? Really? You sure? Functions
  • 45.
    << Header:16, Checksum:4,Payload/binary >>. Bit Syntax
  • 46.
    [ process_payload(Payload) || <<_Header:16, _Checksum:4, Payload/binary>> <= BunchOfData ]. Binary Comprehensions!
  • 47.
    … proc:spawn(fun( X ) -> do_stuff( X ) end ), … do_stuff( OnePerson ) -> change_the_world( OnePerson ). Processes
  • 48.
    if ( Xinstanceof Integer ) { try { change_position( X ); } catch ( ArithmeticException a ) { // can't happen. ignore } catch ( PositionException p ) { // why would this happen? } catch ( Exception e ) { // The other code has this here } catch ( Throwable t ) { // Dunno why this was in the other code vs } } proc:spawn( fun( X ) -> change_position( X ) end ), Defensive Programming
  • 49.
    mahesh#dieswaytoofast.com / @dieswaytoofast  james#2600hz.com / @jamesaimonetti Questions

Editor's Notes

  • #3 Erlang is everywhere. You don’t realize it, but you’re using it. It just works
  • #11 Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  • #12 Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  • #13 Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  • #14 Corresponds to how we think, and helps deal with edge-cases much *much* better!
  • #15 Why wait? Just log on to a node
  • #16 Testing is infinitely easier. Trivial to simulate (its all messages!)
  • #17 Soft real-time. Brief discussion of instrumentation and ‘reductions’
  • #18 Yeah, yeah. And my fish has a bicycle
  • #19 Productivity
  • #24 Because you don’t know how you are going to end up scaling!
  • #25 Really?Yeah, really. Except for FFTs No defensive code, distribution, efficiency
  • #26 Part and parcel of The Erlang WayYou can almost claim that This is how we build Reliable systems!
  • #27 The language is designed from the ground up for concurrency.Why does this even matter? Hold your horses, we’ll get to that in just a moment
  • #28 ‘Distributed’ problems mean you spend a huge chunk of your time dealing with theadminstrivia of distribution.With erlang you get that for free!
  • #29 Ok, not really true. You still have to deal with ‘deep problems’ (hard core parallelization issues, etc.)But you’d have to deal with that anyhow!
  • #30 “Actors”  Think “OO” + “Processes”. Its just that these processes are really cheap
  • #34 Whyerlang? Why not &lt;insert language here&gt;
  • #35 Yup. You can (and people do!) use assembler
  • #36 Don’t shoot yourself in the foot before you get started…
  • #37 Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)
  • #38 Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)
  • #39 One process per session + immutable variables = happiness
  • #42 Garbage Collection, Referential Integrity, Testing!!!
  • #43 Syntactic sugar, but so easy to understand
  • #44 Simple, encapsulated, and discreet casses.
  • #45 And even for JVMs hot-swap is limited to the body of methods
  • #46 Erlang has very useful abstractions that help deal with binary data
  • #47 Trivially easy to process
  • #48 Ridiculously light-weight processes. Trivial to create, Automatically GCd.
  • #49 “Let it Crash!”
  • #50 Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)