Erlang History

45
1/45 A History of Erlang Joe Armstrong HOPL-III [email protected]

Transcript of Erlang History

Page 1: Erlang History

1/45

A History of ErlangJoe Armstrong

HOPL-III

[email protected]

Page 2: Erlang History

2/45

Plan BeginningsWhat is Erlang?Pre historyInnovationsPhilosophySpreading the languageFuture

Page 3: Erlang History

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

Page 4: Erlang History

4/45

What is Erlang?

Page 5: Erlang History

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)

Page 6: Erlang History

6/45

Pre historyAXE – programmed in PLEX

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

Eri Pascal

Page 7: Erlang History

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

Page 8: Erlang History

8/45

1985 - 1998

Page 9: Erlang History

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-

Page 10: Erlang History

10/45

Phoning Philosopher's

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

Page 11: Erlang History

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?

Page 12: Erlang History

12/45

The Prolog interpretor (1986)

version 1.06 dated1986-12-18

1.03 “lost in the mists of time”

Page 13: Erlang History

13/45

The first Erlang operations manual (1986)

Page 14: Erlang History

14/45

Teaching Erlang

Started as Prolog courses

(A pre powerpoint slide - 1986)

Page 15: Erlang History

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”

Page 16: Erlang History

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

Page 17: Erlang History

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

Page 18: Erlang History

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

Page 19: Erlang History

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.

Page 20: Erlang History

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)

Page 21: Erlang History

21/45

Shared memory and

Fault toleranceis

Incredibly difficult

Page 22: Erlang History

22/45

Sharing is the

property that

preventsfault tolerance

Page 23: Erlang History

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

Page 24: Erlang History

24/45

1985 - 1998

Page 25: Erlang History

25/45

What did we learn?

Page 26: Erlang History

26/45

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

Page 27: Erlang History

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)

Page 28: Erlang History

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

Page 29: Erlang History

29/45

Supervision trees

(These are possible because of links)

Page 30: Erlang History

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

Page 31: Erlang History

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”

Page 32: Erlang History

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)

Page 33: Erlang History

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

Page 34: Erlang History

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

Page 35: Erlang History

35/45

Erlang Style Concurrency

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

Page 36: Erlang History

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)

Page 37: Erlang History

37/45

ISS 90

Erlang – the movie

Page 38: Erlang History

38/45

User Conferences

User conferences held every year since 1994 (except 1996)

Page 39: Erlang History

39/45

Does it

work?

Page 40: Erlang History

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

Page 41: Erlang History

41/45

The future

Page 42: Erlang History

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

Page 43: Erlang History

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

Page 44: Erlang History

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)

Page 45: Erlang History

45/45

Questions

download Erlang fromhttp://www.erlang.org