Вы находитесь на странице: 1из 45

A History of Erlang

Joe Armstrong
HOPL-III

joe.armstrong@ericsson.com

1/45
Plan
Beginnings
What is Erlang?
Pre history
Innovations
Philosophy
Spreading the language
Future

2/45
Beginnings
1985 - “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

3/45
What is Erlang?

4/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)

5/45
Pre history
AXE – programmed in PLEX

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

Eri Pascal

6/45
Requirements
- 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

7/45
1985 - 1998

8/45
1985 - 1989
Erlang 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
-

9/45
Phoning Philosopher's

Conclusion – Concurrent Logic


Armstrong, Elshiewy, Virding (1986)
programming with channel
communication
10/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 fifteen


rules. There was just one major problem: the notation only described
how one telephone call should proceed. How could we do this for
thousands of simultaneous calls?

11/45
The Prolog interpretor (1986)
version 1.06 dated
1986-12-18

1.03 “lost in the mists


of time”

12/45
The first Erlang operations manual (1986)

13/45
Teaching Erlang

Started as Prolog courses

14/45
(A pre powerpoint slide - 1986)
1988 – Interpreted Erlang

- 4 days for a complete re-write


- 245 reductions/sec
- semantics of language worked out
- Robert Virding joins the “team”

15/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

16/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

17/45
An early JAM compiler (1989)

sys_sys.erl 18 dummy
sys_parse.erl 783 erlang parser fac(0) -> 1;
sys_ari_parser.erl 147 parse arithmetic expressions fac(N) -> N * fac(N-1)
sys_build.erl 272 build function call arguments
sys_match.erl 253 match function head arguments
sys_compile.erl 708 compiler main program {info, fac, 1}
sys_lists.erl 85 list handling {try_me_else, label1}
sys_dictionary.erl 82 dictionary handler {arg, 0}
sys_utils.erl 71 utilities
sys_asm.erl 419 assembler
{getInt, 0}
sys_tokenise.erl 413 tokeniser {pushInt, 1}
sys_parser_tools.erl 96 parser utilities ret
sys_load.erl 326 loader label1:
sys_opcodes.erl 128 opcode definitions
sys_pp.erl 418 pretty printer try_me_else_fail
sys_scan.erl 252 scanner {arg, 0}
sys_boot.erl 59 bootstrap dup
sys_kernel.erl 9 kernel calls
18 files 4544 {pushInt, 1}
minus
{callLocal, fac, 1}
Like the WAM with added primitives for times
spawning processes and message passing ret
18/45
During development

Robert and I were convinced that


one day we would have to add
destructive operations to the At first the implementation
language, but that we would wait was the only documentation
until a problem that could not be
solved with pure operations turned The manual always lagged
up. behind the implementation

This never happened 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.

19/45
1989 - Clarity
1989 (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 favour


of pure message passing systems)

20/45
Shared memory
and
Fault tolerance
is
Incredibly difficult

21/45
Sharing
is the
property
that
prevents
fault tolerance
22/45
Chronology from 1989 onwards

1989 – JAM – language gets own syntax – things


like receive change
1990 – A reasonable efficient Erlang exists
1991 – Distribution work starts
1993 – Prentice Hall Book – freezes many things
Turbo Erlang (BEAM). Distribution
completed
1995 – AXE-N collapses
1997 – OTP started (a rewrite of BOS)
1997? - Bit syntax and binaries added (for protocol programming )
ets for programming mnesia
1998 – AXD301 announced – Erlang banned – open source Erlang
2006 – SMP Erlang

23/45
1985 - 1998

24/45
What did we learn?

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

26/45
Bit Syntax
- Pattern matching over bits

unpack(<<Red:5,Green:6,Blue:5>>) ->
... -define(IP_VERSION, 4).
-define(IP_MIN_HDR_LEN, 5).

Due to Klacke DgramSize = size(Dgram),


(Claes Vikström) 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.

27/45
(unpack Ipv4 datagram)
Links A is linked to B
B is linked to C

If any process crashes an


A B EXIT message is sent to
the linked processes

This idea comes from the


“C wire” in early telephones
(ground the C wire to cancel the
C
call)

Encourages “let it crash” programming

28/45
Supervision trees

(These are possible because of links)

29/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

30/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”

31/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)

32/45
Concurrency Oriented Programming


A style of programming where
concurrency is used to
structure the application

Large numbers of processes My first message is that

Complete isolation of concurrency
processes is best regarded as a program

No sharing of data structuring principle”

Location transparency
Structured concurrent programming

Pure message passing – Tony Hoare
Redmond, July 2001

33/45
What is COP?

Machine

Process

Message


Large number of processes

Complete isolation between
processes

Location transparency

No Sharing of data

Pure message passing systems
34/45
Erlang Style Concurrency

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

35/45
Spreading the language
1986 – CSLab (Ericsson)
1987 – Bollmora ACS/Dunder starts (First users) (results 1989)
1998 – SETS 1989 (Bournemouth) – contact with John Unger Bellcore
1990 – ISS90 – shown in public
1992 – Concurrent Programming in Erlang (Prentice Hall)
1993 – Erlang systems AB (“Uppsala master's student's”)
1998 – Erlang banned in Ericsson
Open-source Erlang
Blutail
2000 – Bluetail acquired by Alteon , subsequently Nortel
2001 – Dot-com bubble crashes
(This lays the seeds of half a dozen Erlang companies)
2002-2004 – Staying alive - “survival of the fittest”
2004-2007 – Resurgence
2006 – SMP Erlang
2007 - “Programming Erlang” (The Pragmatic Programmers)
“Multicore” erlang works! (New products in Ericsson)
36/45
ISS 90

Erlang – the movie

37/45
User Conferences
User conferences held
every year since 1994
(except 1996)

38/45
Does
it
work?
39/45
Commercial Successes

Ericsson AXD301 (part of “Engine”) (1.1 million lines of Erlang)


Ericsson GPRS system
Alteon (Nortel) SSL accelerator
Alteon (Nortel) SSL VPN
Teba Bank (credit card system – South Africa)
T-mobile SMS system (UK)
Kreditor (Sweden)
Synapse
Tail-f
jabber.org /uses ejabberd)
twitter (uses ejabberd)

40/45
The future

41/45
Erlang is great on multicores

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


multiprocessor?

A: Sometimes (often :-)

Q: Why?

A: No Mutable state + Concurrency

42/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

43/45
Acknowledgements
To Ericsson AB for their support

Bjarne Däcker – ex head of the CS Lab


The 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)

44/45
Questions

download Erlang from


http://www.erlang.org
45/45

Вам также может понравиться