Erlang History

Post on 12-Nov-2014

707 views 2 download

Transcript of Erlang History

1/45

A History of ErlangJoe Armstrong

HOPL-III

joe.armstrong@ericsson.com

2/45

Plan BeginningsWhat is Erlang?Pre historyInnovationsPhilosophySpreading the languageFuture

3/45

Beginnings1985 - “find better ways of programming telephony” SPOTS - LOTS SPOTS = SPC for POTS SPC = Stored Program Control (“computer controlled”) POTS = Plain Ordinary Telephone Service

Write telephony in many different languages

No “plan” to make another programming language

4/45

What is Erlang?

5/45

What is Erlang?- Concurrent (processes belong to Language – NOT OS)- Very light-weight concurrency (lighter than threads)- “Share nothing” process semantics- Pure asynchronous message passing- Core language is a simple dynamically typed FPL- Non-pure extensions (ets) for implementing databases.- Mechanisms for in-service code upgrade- Large set of libraries (OTP) (Unix <-> C <==> OTP <-> Erlang)

6/45

Pre historyAXE – programmed in PLEX

PLEX Programming language for exchanges) Proprietary blocks (processes) and signals in-service code upgrade

Eri Pascal

7/45

- Handling a very large number of concurrent activities- Actions to be performed at a certain point of time or within certain time- Systems distributed over several computers- Interaction with hardware- Very large software systems- Complex functionality such as feature interaction- Continuous operation over several years- Software maintenance (reconfiguration, etc.) without stopping the system- Stringent quality and reliability requirements- Fault tolerance both to hardware failures and software errors

Requirements

8/45

1985 - 1998

9/45

1985 - 1989Erlang is born

- Programming POTS/LOTS/DOTS- A Smalltalk model of POTS- A telephony algebra (math)- A Prolog interpretor for the telephony algebra- I add processes to prolog- Prolog is too powerful (backtracking)- Deterministic prolog with processes- “Erlang” !!!- ...- Compiled to JAM code-

10/45

Phoning Philosopher's

Armstrong, Elshiewy, Virding (1986)Conclusion – Concurrent Logic programming with channel communication

11/45

The Telephony Algebra -(1985)

idle(N) means the subscriber N is idle on(N) means subscribed N in on hook ...

+t(A, dial_tone) means add a dial tone to A process(A, f) :- on(A), idle(A), +t(A,dial-tone), +d(A, []), -idle(A), +of(A)

Using this notation, POTS could be described using fifteenrules. There was just one major problem: the notation only describedhow one telephone call should proceed. How could we do this forthousands of simultaneous calls?

12/45

The Prolog interpretor (1986)

version 1.06 dated1986-12-18

1.03 “lost in the mists of time”

13/45

The first Erlang operations manual (1986)

14/45

Teaching Erlang

Started as Prolog courses

(A pre powerpoint slide - 1986)

15/45

1988 – Interpreted Erlang

- 4 days for a complete re-write- 245 reductions/sec- semantics of language worked out- Robert Virding joins the “team”

16/45

Ways of working

- Light-weight committees- Total rewrite < 1 week- Language feature = one hacking session- Try it out on the users, keep the good stuff- Many different versions- Clear goal – we knew what we wanted to do but not how- Nobody knew what we were doing

17/45

1989 – The need for speed

ACS- Dunder - “we like the language but it's too slow” - must be 40 times faster

Mike Williams writes the emulator (in C)

Joe Armstrong writes the compiler

Robert Virding writes the libraries

18/45

fac(0) -> 1;fac(N) -> N * fac(N-1)

{info, fac, 1} {try_me_else, label1} {arg, 0} {getInt, 0} {pushInt, 1} ret label1: try_me_else_fail {arg, 0} dup {pushInt, 1} minus {callLocal, fac, 1} times ret

sys_sys.erl 18 dummysys_parse.erl 783 erlang parsersys_ari_parser.erl 147 parse arithmetic expressionssys_build.erl 272 build function call argumentssys_match.erl 253 match function head argumentssys_compile.erl 708 compiler main programsys_lists.erl 85 list handlingsys_dictionary.erl 82 dictionary handlersys_utils.erl 71 utilitiessys_asm.erl 419 assembler sys_tokenise.erl 413 tokeniser sys_parser_tools.erl 96 parser utilitiessys_load.erl 326 loadersys_opcodes.erl 128 opcode definitionssys_pp.erl 418 pretty printersys_scan.erl 252 scannersys_boot.erl 59 bootstrapsys_kernel.erl 9 kernel calls18 files 4544

An early JAM compiler (1989)

Like the WAM with added primitives forspawning processes and message passing

19/45

During development

Robert and I were convinced that one day we would have to add destructive operations to the language, but that we would wait until a problem that could not be solved with pure operations turned up.

This never happened

At first the implementation was the only documentation

The manual always lagged behind the implementation

Then when the language matured we decided it should be the other way around. This made life a lot easier.

We wrote the manual and it was “definitive” - not the code.

20/45

1989 - Clarity1989 (SETSS conference Bournemouth)

- Need 2 or more computers for fault-tolerance- If one computer crashes must continue on the other- Cannot share data over processor boundaries- Each computer must be “self contained”- Asynchronous message passing- Failures will occur

(Later these ideas reappear as “isolation” “let it crash”“share nothing” “pure message passing”)

(Implicit rejection of shared-memory systems, in favourof pure message passing systems)

21/45

Shared memory and

Fault toleranceis

Incredibly difficult

22/45

Sharing is the

property that

preventsfault tolerance

23/45

Chronology from 1989 onwards

1989 – JAM – language gets own syntax – things like receive change1990 – A reasonable efficient Erlang exists1991 – Distribution work starts 1993 – Prentice Hall Book – freezes many things Turbo Erlang (BEAM). Distribution

completed1995 – AXE-N collapses1997 – OTP started (a rewrite of BOS)1997? - Bit syntax and binaries added (for protocol programming ) ets for programming mnesia1998 – AXD301 announced – Erlang banned – open source Erlang2006 – SMP Erlang

24/45

1985 - 1998

25/45

What did we learn?

26/45

Innovations- bit syntax- link mechanism- non-defensive programming- pure message passing works

27/45

Bit Syntax - Pattern matching over bits

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

DgramSize = size(Dgram),case Dgram of <<?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, RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize -> OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), <<Opts:OptsLen/binary,Data/binary>> = RestDgram, ...end.

unpack(<<Red:5,Green:6,Blue:5>>) -> ...

Due to Klacke(Claes Vikström)

(unpack Ipv4 datagram)

28/45

Links

A B

C

A is linked to BB is linked to C

If any process crashes anEXIT message is sent to the linked processes

This idea comes from the “C wire” in early telephones(ground the C wire to cancel the call)

Encourages “let it crash” programming

29/45

Supervision trees

(These are possible because of links)

30/45

“let it crash”

- We encourage a non defensive style of programming

- Use worker/supervisor model of programming

- Separation of issues between error detection and recovery and “doing the job” (enabled by light-weight processes, links and process isolation)

- This style of programming is not possible in a single threaded language

31/45

Pure message passing concurrency works

“share nothing” - copy everything programming works for many problems

- This is a surprise to lot's of people- Has it's roots in “ISS89”

32/45

Philosophy –explaining what we're doing

- Logic programming with concurrency (1986)- Declarative programming with concurrency- Functional programming with concurrency- Concurrency with a functional core- Interacting black boxes, governed by protocols where the protocols happen to be implemented in a functional language- Concurrency Oriented Programming (2002)

33/45

Concurrency Oriented Programming

● A style of programming where concurrency is used to structure the application● Large numbers of processes● Complete isolation of processes● No sharing of data● Location transparency● Pure message passing

My first message is that concurrency is best regarded as a program structuring principle”

Structured concurrent programming – Tony Hoare

Redmond, July 2001

34/45

What is COP?

● Large number of processes● Complete isolation between processes● Location transparency● No Sharing of data● Pure message passing systems

Machine

Process

Message

35/45

Erlang Style Concurrency

- Share nothing- Pure message passing- “Let it crash”

36/45

Spreading the language1986 – CSLab (Ericsson)1987 – Bollmora ACS/Dunder starts (First users) (results 1989)1998 – SETS 1989 (Bournemouth) – contact with John Unger Bellcore1990 – ISS90 – shown in public1992 – Concurrent Programming in Erlang (Prentice Hall)1993 – Erlang systems AB (“Uppsala master's student's”)1998 – Erlang banned in Ericsson Open-source Erlang Blutail2000 – Bluetail acquired by Alteon , subsequently Nortel2001 – Dot-com bubble crashes (This lays the seeds of half a dozen Erlang companies)2002-2004 – Staying alive - “survival of the fittest”2004-2007 – Resurgence2006 – SMP Erlang2007 - “Programming Erlang” (The Pragmatic Programmers) “Multicore” erlang works! (New products in Ericsson)

37/45

ISS 90

Erlang – the movie

38/45

User Conferences

User conferences held every year since 1994 (except 1996)

39/45

Does it

work?

40/45

Ericsson AXD301 (part of “Engine”) (1.1 million lines of Erlang)Ericsson GPRS systemAlteon (Nortel) SSL acceleratorAlteon (Nortel) SSL VPN Teba Bank (credit card system – South Africa)T-mobile SMS system (UK)Kreditor (Sweden)SynapseTail-fjabber.org /uses ejabberd)twitter (uses ejabberd)

Commercial Successes

41/45

The future

42/45

Q: Does Erlang run N times faster on an N-core multiprocessor?

A: Sometimes (often :-)

Q: Why?

A: No Mutable state + Concurrency

Erlang is great on multicores

43/45

Lessons Learnt- Message passing concurrency works The extra overhead of copying is unimportant- Isolation is the key property of the language- Processes belong to languages NOT OS's- Pure is fast (enables concurrency)- “share nothing” is fast enough- Don't compromise beauty for efficiency

44/45

AcknowledgementsTo Ericsson AB for their support

Bjarne Däcker – ex head of the CS LabThe Gang of four = (Mike Williams, Robert Virding, Claes Vikström + the author)

Kenneth Lundin and the OTP group at Ericsson

And a cast of hundreds ... (see the paper)

45/45

Questions

download Erlang fromhttp://www.erlang.org