Top Banner
Erlang Solutions Ltd. © 1999-2012 Erlang Solutions Ltd. Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, December 4, 12
31

Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

Aug 29, 2018

Download

Documents

dinhdang
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

Erlang Solutions Ltd.

© 1999-2012 Erlang Solutions Ltd.

Why Erlang is that it is(... and what is it?)

Robert VirdingPrinciple Language ExpertErlang Solutions Ltd.

Tuesday, December 4, 12

Page 2: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Overview

• A bit of history• A bit of philosophy• A few examples

2

Tuesday, December 4, 12

Page 3: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Ancient history

• All started in Ericsson Computer Science Lab• “Everybody” wrote POTS programs to make

phones ring on our MD110 in lab• 1986: First reference to "Erlang" in paper at Logic

conference describing writing telecom apps in concurrent logic

• Joe started programming telephony in Smalltalk based on communicating processes with ideas from CSP- and then started using Prolog

3

Tuesday, December 4, 12

Page 4: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Early history

• Mike and I join the team• First Erlang implementations of Erlang in Prolog• We worked out suitable concurrency and error

detection/handling models- Lots of discussions about this

• Erlang “wanders over” from Prolog to a functional language- Unwanted properties of Prolog

- backtracking and logical variables

4

Tuesday, December 4, 12

Page 5: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Middle ages

• 1990: ISS and “The Movie”- Erlang first presented to the world

• Need more speed for potential product• First Erlang VM, the JAM, developed

- Could now implement dynamic code loading

• Erlang more or less now complete as to basics

5

Tuesday, December 4, 12

Page 6: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Some reflections

• We thought a lot about the problem• Basic “specification” for Erlang system were taken

from AXE10 and PLEX- For example need for, and type of, error handling- Safe language- BUT use conventional hardware and OS

• Very few initial goals as to details of Erlang- It just "became" a functional language- Concurrency and error handling more natural as part

of the language6

Tuesday, December 4, 12

Page 7: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Overview

• A bit of history• A bit of philosophy• A few examples

7

Tuesday, December 4, 12

Page 8: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Basic principles/requirements

• Lightweight, massive concurrency- Asynchronous communication

• Process isolation• Error handling• Continuous evolution of the system

- Dynamic code updating

• Soft real-time• Distribution

8

Tuesday, December 4, 12

Page 9: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Secondary principles/requirements

• Simple high-level language• "Safe" language• Provide tools for building systems, not solutions

- Too limited- (and we usually got them wrong)

9

Tuesday, December 4, 12

Page 10: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Overview

• A bit of history• A bit of philosophy• A few examples

10

Tuesday, December 4, 12

Page 11: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

How Erlang does it

11

Tuesday, December 4, 12

Page 12: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Sequential Language

• Simple functional language- With a “different” syntax

• It is safe!- For example no pointer errors

• It is reasonably high-level- At least then it was

• Dynamically typed

12

Tuesday, December 4, 12

Page 13: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Sequential Language

• Typical features of functional languages- Immutable data- Immutable variables- Extensive use of pattern matching- Recursion rules!

13

Tuesday, December 4, 12

Page 14: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Concurrency

14

• Light-weight “green” processes- Millions of Erlang processes possible on one

machine- and running in a product

• Processes are used for everything- Concurrency- Managing state

• Processes are isolated!• No global data!

Tuesday, December 4, 12

Page 15: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Concurrency: message passing

• Only provide basic primitives• Very cheap asynchronous message passing

- Send a message to a process- Selective receive

- Limits combinatorial explosion in non-deterministic systems

• More complex operations built using send/receive- Synchronous messages built from 2 sends- Error handling complicates matters

15

Tuesday, December 4, 12

Page 16: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Concurrency: message passing• Messages are sent using

the Pid ! Msg expression

• Received messages are stored in the process’s mailbox

• Messages are received using the receive ... end expression

• Messages can be matched and selectively retrieved

• Mailboxes are scanned sequentially.

16

Pid2Pid1

receive start -> ... stop -> ... {Pid,foo} -> ...end

Tuesday, December 4, 12

Page 17: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Concurrency: message passing• Messages are sent using

the Pid ! Msg expression

• Received messages are stored in the process’s mailbox

• Messages are received using the receive ... end expression

• Messages can be matched and selectively retrieved

• Mailboxes are scanned sequentially.

16

Pid2Pid1

Pid2 ! {self(),foo}

{Pid1,foo}

receive start -> ... stop -> ... {Pid,foo} -> ...end

Tuesday, December 4, 12

Page 18: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Concurrency: message passing• Messages are sent using

the Pid ! Msg expression

• Received messages are stored in the process’s mailbox

• Messages are received using the receive ... end expression

• Messages can be matched and selectively retrieved

• Mailboxes are scanned sequentially.

16

Pid2Pid1

Pid2 ! {self(),foo}

{Pid1,foo}

receive start -> ... stop -> ... {Pid,foo} -> ...end

{Pid,foo} -> ...

Tuesday, December 4, 12

Page 19: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling

ERRORS WILL ALWAYS OCCUR!

17

Tuesday, December 4, 12

Page 20: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling

The system must never go down!

Parts may crash and burnBUT

The system must never go down!18

Tuesday, December 4, 12

Page 21: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling

System must be able to- Detect- Contain- Handle- Recover from

errors

19

Tuesday, December 4, 12

Page 22: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Links between processes

• Exit Signals are sent along links when processes terminate abnormally

• The process receiving the signal will exit

• Then propagate a new signal to the processes to which it is linked

20

PidA PidB

Tuesday, December 4, 12

Page 23: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Links between processes

• Exit Signals are sent along links when processes terminate abnormally

• The process receiving the signal will exit

• Then propagate a new signal to the processes to which it is linked

20

PidB

Tuesday, December 4, 12

Page 24: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Links between processes

• Exit Signals are sent along links when processes terminate abnormally

• The process receiving the signal will exit

• Then propagate a new signal to the processes to which it is linked

20

Tuesday, December 4, 12

Page 25: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Processes can trap exit

signals.

• Exit signals will be converted to messages

• They are saved in the process mailbox

• If an exit signal is trapped, it does not propagate further

21

PidAPidB

Tuesday, December 4, 12

Page 26: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Processes can trap exit

signals.

• Exit signals will be converted to messages

• They are saved in the process mailbox

• If an exit signal is trapped, it does not propagate further

21

PidB

Tuesday, December 4, 12

Page 27: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Error handling• Processes can trap exit

signals.

• Exit signals will be converted to messages

• They are saved in the process mailbox

• If an exit signal is trapped, it does not propagate further

21

PidB

Tuesday, December 4, 12

Page 28: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Robust systems

How do you build robust systems?

• You need to ensure- Necessary functionality always available- System cleans up when things go wrong

• Must have at least two machines!- Need distribution

22

Tuesday, December 4, 12

Page 29: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

• Supervisors will start child processes- Workers- Supervisors

• Supervisors will monitortheir children- Through links and trapping exits

• Supervisors can restart thechildren when they terminate

Robust systems: Supervision trees

23

Supervisors

Workers

Tuesday, December 4, 12

Page 30: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Robust systems: Monitor processes

• Servers monitoring clients- Clean-up after then if they crash

• Processes monitoring co-workers• Groups of co-workers dying together

24

Tuesday, December 4, 12

Page 31: Why Erlang is that it is ( and what is it?) · Why Erlang is that it is (... and what is it?) Robert Virding Principle Language Expert Erlang Solutions Ltd. Tuesday, ... phones ring

© 1999-2012 Erlang Solutions Ltd.

Code handling

• Module is the unit of all code handling- No inter-module dependencies

- Causes problems with static typing

• Have two versions of each module- Old and current- Allows controlled take-over

• Well defined behaviour with respect to code- You KNOW what happens when you call a function- You KNOW what happens when you load a module

25

Tuesday, December 4, 12