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

Más contenido relacionado

Similar a Why Erlang is Ideal for Building Scalable and Reliable Systems

Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014Greg Vaughn
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
Erlang/OTP for Rubyists
Erlang/OTP for RubyistsErlang/OTP for Rubyists
Erlang/OTP for RubyistsSean Cribbs
 
Getting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsGetting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsSaurabh Nanda
 
Elixir - GDG - Nantes
Elixir - GDG - NantesElixir - GDG - Nantes
Elixir - GDG - NantesAxel CATELAND
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptAung Baw
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-finalMarcus Lagergren
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Testing stateful, concurrent, and async systems using test.check
Testing stateful, concurrent, and async systems using test.checkTesting stateful, concurrent, and async systems using test.check
Testing stateful, concurrent, and async systems using test.checkEric Normand
 
Artificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with ParallelismArtificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with ParallelismOlivier Teytaud
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Turning Ideas Into Code Faster
Turning Ideas Into Code FasterTurning Ideas Into Code Faster
Turning Ideas Into Code Fastermeysholdt
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScriptRevath S Kumar
 

Similar a Why Erlang is Ideal for Building Scalable and Reliable Systems (20)

Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Erlang/OTP for Rubyists
Erlang/OTP for RubyistsErlang/OTP for Rubyists
Erlang/OTP for Rubyists
 
Rakudo
RakudoRakudo
Rakudo
 
Getting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 yearsGetting property based testing to work after struggling for 3 years
Getting property based testing to work after struggling for 3 years
 
Elixir - GDG - Nantes
Elixir - GDG - NantesElixir - GDG - Nantes
Elixir - GDG - Nantes
 
Wrong
WrongWrong
Wrong
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Fp
FpFp
Fp
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-final
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Querydsl overview 2014
Querydsl overview 2014Querydsl overview 2014
Querydsl overview 2014
 
Testing stateful, concurrent, and async systems using test.check
Testing stateful, concurrent, and async systems using test.checkTesting stateful, concurrent, and async systems using test.check
Testing stateful, concurrent, and async systems using test.check
 
Artificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with ParallelismArtificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with Parallelism
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Turning Ideas Into Code Faster
Turning Ideas Into Code FasterTurning Ideas Into Code Faster
Turning Ideas Into Code Faster
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScript
 

Más de Mahesh Paolini-Subramanya

Active Queue Management (for Cloud Services)
Active Queue Management (for Cloud Services)Active Queue Management (for Cloud Services)
Active Queue Management (for Cloud Services)Mahesh Paolini-Subramanya
 
What I did on my Vacation (hint: Scuba & Erlang)
What I did on my Vacation (hint: Scuba & Erlang)What I did on my Vacation (hint: Scuba & Erlang)
What I did on my Vacation (hint: Scuba & Erlang)Mahesh Paolini-Subramanya
 
Your business depends your customers - keeping them in the loop
Your business depends your customers - keeping them in the loop Your business depends your customers - keeping them in the loop
Your business depends your customers - keeping them in the loop Mahesh Paolini-Subramanya
 
VoIP applications and the Cloud - Where gen_fsm really shines
VoIP applications and the Cloud - Where gen_fsm really shines VoIP applications and the Cloud - Where gen_fsm really shines
VoIP applications and the Cloud - Where gen_fsm really shines Mahesh Paolini-Subramanya
 

Más de Mahesh Paolini-Subramanya (6)

Active Queue Management (for Cloud Services)
Active Queue Management (for Cloud Services)Active Queue Management (for Cloud Services)
Active Queue Management (for Cloud Services)
 
NoSQL learnings from the world of Telco
NoSQL learnings from the world of TelcoNoSQL learnings from the world of Telco
NoSQL learnings from the world of Telco
 
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
 
What I did on my Vacation (hint: Scuba & Erlang)
What I did on my Vacation (hint: Scuba & Erlang)What I did on my Vacation (hint: Scuba & Erlang)
What I did on my Vacation (hint: Scuba & Erlang)
 
Your business depends your customers - keeping them in the loop
Your business depends your customers - keeping them in the loop Your business depends your customers - keeping them in the loop
Your business depends your customers - keeping them in the loop
 
VoIP applications and the Cloud - Where gen_fsm really shines
VoIP applications and the Cloud - Where gen_fsm really shines VoIP applications and the Cloud - Where gen_fsm really shines
VoIP applications and the Cloud - Where gen_fsm really shines
 

Why Erlang is Ideal for Building Scalable and Reliable Systems

  • 1. Erlang FTW! { Mahesh Paolini-Subramanya (@dieswaytoofast) V.P. Ubiquiti Networks James Aimonetti (@jamesaimonetti)
  • 4. Horizontal Scalability
  • 5. Horizontal Scalability
  • 6. Horizontal  Vertical Scalability
  • 7. Horizontal  Vertical Scalability
  • 8. Live! Hot Swapping
  • 9. Live! Hot Swapping
  • 18. 4x – 10x less 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
  • 24. Speed
  • 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
  • 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/…)
  • 35.
  • 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 ( 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
  • 49. mahesh#dieswaytoofast.com / @dieswaytoofast  james#2600hz.com / @jamesaimonetti Questions

Notas del editor

  1. Erlang is everywhere. You don’t realize it, but you’re using it. It just works
  2. Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  3. Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  4. Its how the world works. ‘Synchronous’ and ‘semaphore’ and ‘mutex’ are all (artificial) programming constructs
  5. Corresponds to how we think, and helps deal with edge-cases much *much* better!
  6. Why wait? Just log on to a node
  7. Testing is infinitely easier. Trivial to simulate (its all messages!)
  8. Soft real-time. Brief discussion of instrumentation and ‘reductions’
  9. Yeah, yeah. And my fish has a bicycle
  10. Productivity
  11. Because you don’t know how you are going to end up scaling!
  12. Really?Yeah, really. Except for FFTs No defensive code, distribution, efficiency
  13. Part and parcel of The Erlang WayYou can almost claim that This is how we build Reliable systems!
  14. 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
  15. ‘Distributed’ problems mean you spend a huge chunk of your time dealing with theadminstrivia of distribution.With erlang you get that for free!
  16. 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!
  17. “Actors”  Think “OO” + “Processes”. Its just that these processes are really cheap
  18. Whyerlang? Why not &lt;insert language here&gt;
  19. Yup. You can (and people do!) use assembler
  20. Don’t shoot yourself in the foot before you get started…
  21. Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)
  22. Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)
  23. One process per session + immutable variables = happiness
  24. Garbage Collection, Referential Integrity, Testing!!!
  25. Syntactic sugar, but so easy to understand
  26. Simple, encapsulated, and discreet casses.
  27. And even for JVMs hot-swap is limited to the body of methods
  28. Erlang has very useful abstractions that help deal with binary data
  29. Trivially easy to process
  30. Ridiculously light-weight processes. Trivial to create, Automatically GCd.
  31. “Let it Crash!”
  32. Yeah, yeah. Understandable lies. But the bottlenecks are pretty far down the road (and much further than you would have gotten before!)