Erlang FTW!

49
{ Erlang FTW! Mahesh Paolini-Subramanya (@dieswaytoofast) V.P. Ubiquiti Networks James Aimonetti (@jamesaimonetti)

description

In the Brave New World of cloud computing, fault tolerance is king. Fault tolerance at all levels - the platform, how and where the data is stored, the services and APIs that are used, and even the ability to recover from bugs ("features"?) in the code. This emphasis has resulted in the growing use of actor programming over object-oriented programming, and in particular, the growing influence of Erlang wherever Reliability and Scalability are prized. This talk will explore the reason why Erlang is particularly suited for Cloud Applications and Services, and why it should be the basis for your App's infrastructure

Transcript of Erlang FTW!

Page 1: Erlang FTW!

{Erlang FTW!

Mahesh Paolini-Subramanya (@dieswaytoofast)V.P. Ubiquiti NetworksJames Aimonetti (@jamesaimonetti)

Page 2: Erlang FTW!

Erlang Everywhere

Page 3: Erlang FTW!

Why Erlang?

Page 4: Erlang FTW!

Horizontal

Scalability

Page 5: Erlang FTW!

Horizontal

Scalability

Page 6: Erlang FTW!

Horizontal

Vertical

Scalability

Page 7: Erlang FTW!

Horizontal

Vertical

Scalability

Page 8: Erlang FTW!

Live!

Hot Swapping

Page 9: Erlang FTW!

Live!

Hot Swapping

Page 10: Erlang FTW!

Asynchronous Processing

Page 11: Erlang FTW!

Asynchronous Processing

Page 12: Erlang FTW!

Asynchronous Processing

Page 13: Erlang FTW!

Supervision

Page 14: Erlang FTW!

Live Debugging

Page 15: Erlang FTW!

Stack Traces

Page 16: Erlang FTW!

Predictability

Page 17: Erlang FTW!

Why Erlang?

Page 18: Erlang FTW!

4x – 10x less code

Page 19: Erlang FTW!

Faster to create

4x – 10x less code

Page 20: Erlang FTW!

Faster to create

Easier to reason about

4x – 10x less code

Page 21: Erlang FTW!

Faster to create

Easier to reason about

Fewer bugs

4x – 10x less code

Page 22: Erlang FTW!

Faster to create

Easier to reason about

Fewer bugs

Speedy refactoring

4x – 10x less code

Page 23: Erlang FTW!

Scalability

vs

Page 24: Erlang FTW!

Speed

Page 25: Erlang FTW!

Reliability

Page 26: Erlang FTW!

Concurrency by default

Error encapsulation

Fault detection

Fault identification

Code upgrade

Stable Storage

Concurrency Oriented

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

Page 27: Erlang FTW!

Concurrency Oriented

Concurrency Hell

My Blue Heaven My Blue Heaven

Page 28: Erlang FTW!

Concurrency Oriented

Concurrency Hell

My Blue Heaven

Deep Problems

My Blue Heaven

Deep Problems

Page 29: Erlang FTW!

Cheap Actors

Page 30: Erlang FTW!

Shared vs shared-nothing

OO vs Actors

Page 31: Erlang FTW!

Shared vs shared-nothing

Inheritance vs Behavior

OO vs Actors

Page 32: Erlang FTW!

Shared vs shared-nothing

Inheritance vs Behavior

Sync vs Async

OO vs Actors

Page 33: Erlang FTW!

Why Not Java? (Ruby/…)

Page 34: Erlang FTW!

Why not assembler?

Page 35: Erlang FTW!
Page 36: Erlang FTW!

Trivial thread management (hint: none)

Erlang Architecture

Page 37: Erlang FTW!

Trivial thread management (hint: none)

Trivial monitoring / load-balancing

Erlang Architecture

Page 38: Erlang FTW!

Trivial thread management (hint: none)

Trivial monitoring / load-balancing

One process per session

Erlang Architecture

Page 39: Erlang FTW!

Immutable Variables

X = 1.

Page 40: Erlang FTW!

Immutable Variables

X = 1.

X = 2.

Huh?

Page 41: Erlang FTW!

Immutable Variables

X = 1.

X = 2.

X = X + 1.

Huh?

Page 42: Erlang FTW!

List Comprehensions

[ do_something_with(X) || X <- ListOfItems ]

Page 43: Erlang FTW!

Functions

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

greet( male, Name ) ->print_out( “Hello Mr. ”, Name );

greet( female, Name ) ->print_out( “Greetings Mrs. ”, Name );

greet( _, Name ) ->print_out( “Wotcher ”, Name ).

vs

From http://learnyousomeerlang.com/

Page 44: Erlang FTW!

Functions

Module:code_change( OldVersion, OldState, Stuff ) ->

NewState = whatever_you_need_to_do( OldVersion, OldState, Stuff ),

{ ok, NewState }.

vsMonkey Patching?

Really?

You sure?

Page 45: Erlang FTW!

Bit Syntax

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

Page 46: Erlang FTW!

Binary Comprehensions!

[ process_payload(Payload) || <<_Header:16, _Checksum:4, Payload/binary>>

<= BunchOfData ].

Page 47: Erlang FTW!

Processes

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

do_stuff( OnePerson ) -> change_the_world( OnePerson ).

Page 48: Erlang FTW!

Defensive Programming

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}

}

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

vs

Page 49: Erlang FTW!

mahesh#dieswaytoofast.com / @dieswaytoofast

james#2600hz.com / @jamesaimonetti

Questions