Erlang FTW!
-
Upload
mahesh-paolini-subramanya -
Category
Documents
-
view
880 -
download
2
description
Transcript of Erlang FTW!
{Erlang FTW!
Mahesh Paolini-Subramanya (@dieswaytoofast)V.P. Ubiquiti NetworksJames 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
Scalability
vs
Speed
Reliability
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
Concurrency Oriented
Concurrency Hell
My Blue Heaven My Blue Heaven
Concurrency Oriented
Concurrency Hell
My Blue Heaven
Deep Problems
My Blue Heaven
Deep Problems
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
Immutable Variables
X = 1.
Immutable Variables
X = 1.
X = 2.
Huh?
Immutable Variables
X = 1.
X = 2.
X = X + 1.
Huh?
List Comprehensions
[ do_something_with(X) || X <- ListOfItems ]
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/
Functions
Module:code_change( OldVersion, OldState, Stuff ) ->
NewState = whatever_you_need_to_do( OldVersion, OldState, Stuff ),
{ ok, NewState }.
vsMonkey Patching?
Really?
You sure?
Bit Syntax
<< Header:16, Checksum:4, Payload/binary >>.
Binary Comprehensions!
[ process_payload(Payload) || <<_Header:16, _Checksum:4, Payload/binary>>
<= BunchOfData ].
Processes
…proc:spawn( fun( X ) -> do_stuff( X ) end ),…
do_stuff( OnePerson ) -> change_the_world( OnePerson ).
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
mahesh#dieswaytoofast.com / @dieswaytoofast
james#2600hz.com / @jamesaimonetti
Questions