erlang for five nines

33
Erlang for Five Nines Erlang for Five Nines bar bar camp camp Cork III Cork III Tamas Nagy [email protected] © 1999 – 2009 Erlang Training and Consulting Ltd © 1999 – 2009 Erlang Training and Consulting Ltd

Upload: barcamp-cork

Post on 13-Nov-2014

6.056 views

Category:

Technology


2 download

DESCRIPTION

Erlang for Five Nines presentation for Barcamp 2009

TRANSCRIPT

Page 1: Erlang For Five Nines

Erlang for Five NinesErlang for Five Nines

barbarcampcampCork IIICork III

Tamas [email protected]

© 1999 – 2009 Erlang Training and Consulting Ltd© 1999 – 2009 Erlang Training and Consulting Ltd

Page 2: Erlang For Five Nines

Page 2

ContentsContents

• Erlang HistoryErlang History• Erlang HighlightsErlang Highlights• ProductsProducts• QuestionsQuestions

Page 3: Erlang For Five Nines

Page 3

Erlang History: The Telecom IndustryErlang History: The Telecom Industry

• ComplexComplex• ReliableReliable• ScalableScalable• DistributedDistributed• MaintainablMaintainabl

ee• HighlyHighly

AvailableAvailable

• versusversus

Time To Time To Market!Market!

Access transport and switching networks

CellularPLMN

PSTN/ISDN

Data/ IPNetworks

CATV

Services

Past Single-service networks

Clients/applications

PresentMultiservice networks/client server

BackboneNetwork

Access

Access

Access

Content Content

ControlCommunication

applicationsMedia

Gateways

Page 4: Erlang For Five Nines

Page 4

Erlang HistoryErlang History

1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998

Prototypes of Telecom

applications

First projects launched

First products launched

Major projects started

OTP R1 released

Releasedas Open Source

Experiments started at the

Computer Science Lab

“Find the right methods - design by prototyping.”

Mike Willliams, CS LAB

Make mistakes on a small scale, not in a production project.

Mike Willliams

It’s not good enough to have ideas – you must also be able to implement them to

know that they work

Mike Willliams

And the rest is history...

First Erlang Book Published

First C-Based Virtual Machine

Page 5: Erlang For Five Nines

Page 5

And this is just the beginning...

“Erlang is going to be a very important language.It could be the next Java.”

Ralph JohnsonCo-author, “Design Patterns” (the “Gang-of-Four book”)

To build a large scale message handling system that really had to be up all the time, I would unhesitatingly choose Erlang….

Tim BraySun Microsystems

…if we had to start again we would probably use Erlang…

Mike ShaverMozilla Foundation

Erlang HistoryErlang History

1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 The Future

January, 36,000 hits on

erlang.org

Bluetail AB acquired for 152M USD

August, 1 million hits on

erlang.org

Erlang R11 goes multicore

The first Erlang Factory

Major new projects started within Ericsson

ETC is founded

Page 6: Erlang For Five Nines

Page 6

Requests to erlang.orgRequests to erlang.org

Page 7: Erlang For Five Nines

Page 7

ContentsContents

• Erlang HistoryErlang History• Erlang HighlightsErlang Highlights• ProductsProducts• QuestionsQuestions

Page 8: Erlang For Five Nines

Page 8

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Functional programming language

High abstraction levelPattern matching

Concise readable programs

Page 9: Erlang For Five Nines

Page 9

Erlang Highlights: FactorialErlang Highlights: Factorial

n! =1

n*(n-1)!

n = 0

n 1

Definition

-module(ex1).-export([factorial/1]).

factorial(0) -> 1;factorial(N) when N >= 1 -> N * factorial(N-1).

Implementation

Eshell V5.0.1 (abort with ^G)1> c(ex1).{ok,ex1}2> ex1:factorial(6).720

Factorial using Recursion

Page 10: Erlang For Five Nines

Page 10

Erlang Highlights: High-level Erlang Highlights: High-level ConstructsConstructs

-define(IP_VERSION, 4).-define(IP_MIN_HDR_LEN, 5).

……DgramSize = size(Dgram), <<?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, Body/binary>> = Dgram, if (HLen >= 5) and (4*HLen =< DgramSize) -> OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), <<Opts:OptsLen/binary, Data/binary>> = Body, ….. end.

Parsing an IP Datagram using the Bit Syntax

Page 11: Erlang For Five Nines

Page 11

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Either transparent or explicit concurrency

Light-weight processesHighly scalable

Page 12: Erlang For Five Nines

Page 12

Erlang Highlights: ConcurrencyErlang Highlights: Concurrency

Creating a new process using spawn

-module(ex3).-export([activity/3]).

activity(Name,Pos,Size) -> …………

Pid = spawn(ex3,activity,[Joe,75,1024])

activity(Joe,75,1024)

Page 13: Erlang For Five Nines

Page 13

Erlang Highlights: ConcurrencyErlang Highlights: Concurrency

10 100 1,000 10,000 100,000Number of processes1

10

100

1,000

Mic

rose

con

ds/

pro

cess

erlang

java

C#

Source:Joe ArmstrongSICS

Processcreationtime

Page 14: Erlang For Five Nines

Page 14

Erlang Highlights: ConcurrencyErlang Highlights: ConcurrencyProcesses communicate by asynchronous message passing

Pid ! {data,12,13} receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ………end

receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ………end

Page 15: Erlang For Five Nines

Page 15

Erlang Highlights: ConcurrencyErlang Highlights: Concurrency

10 100 1,000 10,000 100,000Number of processes1

10

1,000

100,000

Mic

rose

con

ds/

mes

sage

erlang

java

C#

10,000

100

1Source:Joe ArmstrongSICS

Messagepassingtimes

Page 16: Erlang For Five Nines

Page 16

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Response times in theorder of milliseconds

Per-process garbage collection

Page 17: Erlang For Five Nines

Page 17

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Simple and consistenterror recovery

Supervision hierarchies"Program for the correct case"

Page 18: Erlang For Five Nines

Page 18

Erlang Highlights: RobustnessErlang Highlights: RobustnessRobust systems can be built by layering

“Supervisors”

“Workers”

Page 19: Erlang For Five Nines

Page 19

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Explicit or transparent distribution

Network-awareruntime system

Page 20: Erlang For Five Nines

Page 20

Erlang Highlights: DistributionErlang Highlights: Distribution

Erlang Run-Time SystemErlang Run-Time System Erlang Run-Time SystemErlang Run-Time System

B ! Msg

network

C ! Msg

Page 21: Erlang For Five Nines

Page 21

Erlang Highlights: DistributionErlang Highlights: Distribution

loop() -> receive {From, {apply, M, F, A}} -> Answer = apply(M, F, A), From ! {rex, node(), Answer} loop(); _Other -> loop() end.

{rex, Node} ! {self(), {apply, M, F, A}},receive {rex, Node, What} -> Whatend

{rex, Node} ! {self(), {apply, M, F, A}},receive {rex, Node, What} -> Whatend

{rex, Node} ! {self(), {apply, M, F, A}},receive {rex, Node, What} -> Whatend

loop() -> receive {From, {apply, M, F, A}} -> Answer = apply(M, F, A), From ! {rex, node(), Answer} loop(); _Other -> loop() end.

loop() -> receive {From, {apply, M, F, A}} -> Answer = apply(M, F, A), From ! {rex, node(), Answer} loop(); _Other -> loop() end.

loop() -> receive {From, {apply, M, F, A}} -> Answer = apply(M, F, A), From ! {rex, node(), Answer} loop(); _Other -> loop() end.

Simple Remote Procedure Call

Page 22: Erlang For Five Nines

Page 22

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Easily change code in a running system

Enables non-stop operationSimplifies testing

Page 23: Erlang For Five Nines

Page 23

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

"Ports" to the outside worldbehave as Erlang processes

Page 24: Erlang For Five Nines

Page 24

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Erlang runs on a Virtual Machine ported to UNIX,

Windows, VxWorks, OS X, …Supports heterogeneous

networks.

Page 25: Erlang For Five Nines

Page 25

Erlang HighlightsErlang Highlights

• DeclarativeDeclarative• ConcurrencyConcurrency• Soft real-timeSoft real-time• RobustnessRobustness• DistributionDistribution• Hot code loadingHot code loading• External interfacesExternal interfaces• PortabilityPortability• SMP SupportSMP Support

Symmetric multiprocessing support. Takes full advantage

of multiple CPU architectures.

Page 26: Erlang For Five Nines

Page 26

Erlang SMPErlang SMP

Erlang VM

Scheduler

run queue

non-SMP VM

Erlang VM

Scheduler #1

Scheduler #2

Scheduler #N

migration logic

run queue

run queue

run queue

SMP VM

Page 27: Erlang For Five Nines

Page 27

ContentsContents

• Erlang HistoryErlang History• Erlang HighlightsErlang Highlights• ProductsProducts• QuestionsQuestions

Page 28: Erlang For Five Nines

Page 28

Products: Ericsson AXD301 SwitchProducts: Ericsson AXD301 Switch• A Telephony-Class, scalable (10 –A Telephony-Class, scalable (10 –

160 GBps) 160 GBps) ATM switch ATM switch

• Designed from scratch in less than 3 Designed from scratch in less than 3 yearsyears

– Proof of concept in three months– 1.5 million lines of Erlang code in the OM– 500,000 lines of C/C++ in the switch core– 13,000 lines of Java in the GUI

• AXD 301 Success factors:AXD 301 Success factors:– Competent organisation and people– Efficient process– Excellent technology (Erlang!)

Page 29: Erlang For Five Nines

Page 29

Products: Ericsson AXD301 SwitchProducts: Ericsson AXD301 Switch

• Using Erlang in Complex SystemsUsing Erlang in Complex Systems– Fits very well with the incremental design method– High programmer satisfaction– Outstanding support for robustness and concurrency– Very few side-effects easier to add/change single

components– Small directed teams can achieve impressive results

• Productivity estimatesProductivity estimates– Similar line/hour programmer productivity– 4-10 fewer lines of source code (compared to C/C++, Java,

PLEX)– Similar number of faults per 1000 lines of source code

Page 30: Erlang For Five Nines

Page 30

Erlang: It’s Happening!Erlang: It’s Happening!Amazon

Simple DB

Yahoo! Delicious

T-Mobile WAP, SMS, IN services

Facebook Chat channel servers

Powerset/Microsoft Key/Value store

37 SignalsBackend servers

Page 31: Erlang For Five Nines

Page 31

CouchDB Distributed Robust document database

Wings 3D 3D modeller based on Nendo

YAWS Yet Another Web Server

RabbitMQ High performance enterprise messaging

Ejabberd XMPP instant messaging server

Erlang: It’s Happening!Erlang: It’s Happening!

Page 32: Erlang For Five Nines

Page 32

QuestionsQuestions

Page 33: Erlang For Five Nines

Page 33

www.planeterlang.org

www.trapexit.org

www.erlang-factory.com

www.erlang-consulting.com

www.erlang.org