2001-03-19 etx/d/xps-01:002 uen 1 bjarne däcker computer science laboratory ericsson utvecklings ab...
TRANSCRIPT
2001-03-19 ETX/D/XPS-01:002 Uen 1
Bjarne Däcker <[email protected]>Computer Science Laboratory
Ericsson Utvecklings AB
Acknowledgements
Thomas Arts <[email protected]>
Hans Nilsson <[email protected]>
Torbjörn Keisu <[email protected]>
Ulf Wiger <[email protected]>
Concurrent Functional Programming with Erlang and OTP (Open Telecom
Platform)
2001-03-19 ETX/D/XPS-01:002 Uen 2
The setting
1995 PC Week Study of software projects:– 16% successful
– 53% operational (but less than successful)
– 31% cancelled
Butler Group 1997 on large software projects– 5 out of 6 large projects fail
– In >$300M companies, 9 out of 10 large projects fail
How to approach this?– Use high-level modeling tools & generate code?
– Raise the level of programming language?
– Fight all causes for project failure!
2001-03-19 ETX/D/XPS-01:002 Uen 3
Telecom industry
Switches, routers,
base-stations Networks Mobile telephones
2001-03-19 ETX/D/XPS-01:002 Uen 4
Requirements on a Programming Technology for Telecommunication Switching Systems
Massive concurrency Soft realtime Distribution Interaction with hardware Very large software systems Complex functionality Continuous operation for many years Software maintenance without stopping the system Stringent quality and reliability requirements Fault tolerance errors
2001-03-19 ETX/D/XPS-01:002 Uen 5
History of Erlang
1984:EricssonComputerScience Labformed
1984-86:ExperimentsprogrammingPOTS with several languages
1998:Open SourceErlang
1987:Early ErlangPrototype projects
1991:First fastimplementation
1993:DistributedErlang
1995:Severalnew projects
1996:Open Telecom Platform(research on verification...)
No language well suitedfor telecom systems
development
2001-03-19 ETX/D/XPS-01:002 Uen 6
The Ancestry of Erlang
Functional programming languages like ML or
Miranda
Concurrent systems programming languages like Ada, Modula or Chill
Concurrent functional programming language
Erlang
2001-03-19 ETX/D/XPS-01:002 Uen 7
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Functional programming languageHigh abstraction level
Pattern matchingConcise readable programs
2001-03-19 ETX/D/XPS-01:002 Uen 8
Erlang Example
Basics - Factorial function
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
2001-03-19 ETX/D/XPS-01:002 Uen 9
Erlang Example
A few very high-level constructs - QuickSort
-module(ex2).-export([qsort/1]).
qsort([Head|Tail]) -> First = qsort([X || X <- Tail, X =< Head]), Last = qsort([Y || Y <- Tail, Y > Head]), First ++ [Head|Last];qsort([]) -> [].
Eshell V5.0.1 (abort with ^G)1> c(ex2). {ok,ex2}2> ex2:qsort([7,5,3,8,1]).[1,3,5,7,8]
"all objects Y taken from the list Tail,
where Y > Head"
2001-03-19 ETX/D/XPS-01:002 Uen 10
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Either transparent or explicit concurrency
Light-weight processesHighly scalable
2001-03-19 ETX/D/XPS-01:002 Uen 11
Erlang Example
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)activity(Joe,75,1024)
2001-03-19 ETX/D/XPS-01:002 Uen 12
Erlang Example
Processes communicate by asynchronous message passing
Pid ! {data,12,13} receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ………end
receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ………end
2001-03-19 ETX/D/XPS-01:002 Uen 13
Erlang Example
Concurrency - Finite State Machine
ringing_a(A, B) -> receive {A, on_hook} -> back_to_idle(A, B); {B, answered} -> A ! {stop_tone, ring}, switch ! {connect, A, B}, conversation_a(A, B) after 30000 -> back_to_idle(A, B)end.
back_to_idle(A, B) -> A ! {stop_tone, ring}, B ! terminate, idle(A).
Selective receive
Asynchronous send
Optional timeout
2001-03-19 ETX/D/XPS-01:002 Uen 14
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Response times in theorder of milliseconds
Per-process garbage collection
2001-03-19 ETX/D/XPS-01:002 Uen 15
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Simple and consistenterror recovery
Supervision hierarchies"Program for the correct case"
2001-03-19 ETX/D/XPS-01:002 Uen 16
Erlang Example
Cooperating processes may be linked together
usingspawn_link(…,…,…)orlink(Pid)
2001-03-19 ETX/D/XPS-01:002 Uen 17
Erlang Example
When a process terminates, an exit signal is sent to all linked processes
… and the termination is propagated
2001-03-19 ETX/D/XPS-01:002 Uen 18
Erlang Example
Exit signals can be trapped and received as messages
receive {‘EXIT’,Pid,...} -> ...end
2001-03-19 ETX/D/XPS-01:002 Uen 19
Erlang Example
Robust systems can be built by layering
“Supervisors”
“Workers”
2001-03-19 ETX/D/XPS-01:002 Uen 20
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Explicit or transparent distributionNetwork-aware runtime system
2001-03-19 ETX/D/XPS-01:002 Uen 21
Transparent Distribution
Erlang Run-Time SystemErlang Run-Time System Erlang Run-Time SystemErlang Run-Time System
B ! Msg
network
C ! Msg
2001-03-19 ETX/D/XPS-01:002 Uen 22
Simple RPC
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.
2001-03-19 ETX/D/XPS-01:002 Uen 23
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Easily change code in a running system
Enables non-stop operationSimplifies testing
2001-03-19 ETX/D/XPS-01:002 Uen 25
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
"Ports" to the outside worldbehave as Erlang processes
2001-03-19 ETX/D/XPS-01:002 Uen 26
Erlang Example
PortPort Externalprocess
Externalprocess
Port ! {self(), {command, [1,2,3]}}
2001-03-19 ETX/D/XPS-01:002 Uen 27
Erlang Example
PortPort Externalprocess
Externalprocess
receive {Port, {data, Info}} ->end
2001-03-19 ETX/D/XPS-01:002 Uen 28
Erlang Highlights
DeclarativeConcurrencySoft real-timeRobustnessDistributionHot code loadingExternal interfacesPortability
Erlang runs on any UNIX,Windows, VxWorks, ...Supports heterogeneous
networks
2001-03-19 ETX/D/XPS-01:002 Uen 29
OTP ComponentsOTP Components
Standard LibrariesStandard Libraries
Erlang Run-Time SystemErlang Run-Time System
Hardware and Operating SystemHardware and Operating System
Applications written in Erlang
Applicationswritten in C,C++ or Java
Systems Overview
2001-03-19 ETX/D/XPS-01:002 Uen 30
Erlang/OTP
Open Telecom PlatformMiddleware for Erlang developmentDesigned for fault tolerance and portabilityBehaviors: A formalization of design patternsComponents
– Error handling, reporting and logging
– Mnesia, distributed real-time database management system
– CORBA
– IDL Compiler, Java & C Interface Support
– HTTP Server
– SNMP Agent
– ...
2001-03-19 ETX/D/XPS-01:002 Uen 31
OTP Behaviors
"A formalization of design patterns"– A behavior is a framework
+ generic code to solve a common problem
– Each behavior has built-in support fordebugging and software upgrade
– Makes it easier to reason about the behavior of a program
Examples of OTP behaviors– application defines how an application is implemented
– supervisor used to write fault-tolerant supervision trees
– gen_server for writing client-server applications
– gen_event for writing event handlers
– gen_fsm for finite state machine programming
2001-03-19 ETX/D/XPS-01:002 Uen 32
The standard textbook
Joe Armstrong, Robert Virding, Claes Wikström and Mike Williams, Concurrent Programming in Erlang, Prentice Hall, 1996,2nd edition, ISBN 0-13-508301-X
2001-03-19 ETX/D/XPS-01:002 Uen 33
Interesting web pagesOpen source Erlangwww.erlang.org
Commercial Erlangwww.erlang.se
French Erlang sitewww.erlang-fr.org
2001-03-19 ETX/D/XPS-01:002 Uen 34
Courses/year (10-15 pupils/course)
0
5
10
15
20
25
30
35
40
45
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001-03-19 ETX/D/XPS-01:002 Uen 35
Requests/month to www.erlang.org
020000400006000080000
100000120000140000160000180000200000
no
v-98
mar
-99
jul-
99
no
v-99
mar
-00
jul-
00
no
v-00
mar
-01
jul-
01
2001-03-19 ETX/D/XPS-01:002 Uen 36
Downloads/month from www.erlang.org
0500
1000150020002500n
ov-
98
mar
-99
jul-
99
no
v-99
mar
-00
jul-
00
no
v-00
mar
-01
jul-
01
2001-03-19 ETX/D/XPS-01:002 Uen 37
AXD 301: A Telephony-Class, scalable (10-160 GBps) ATM switchdesigned from scratch in less than 3 years
AXD 301 Success factors:– Highly pragmatic, holistic approach
– Competent organisation
– Efficient process
– Excellent technology (e.g. Erlang/OTP)
More than just technology...– Consider all factors together from the start
– Erlang was a perfect match for our approach
2001-03-19 ETX/D/XPS-01:002 Uen 38
ENGINE:Migrating today's vertical networksinto a single multi-service backbone
AXD 301 in the marketplace
Central component in Ericsson's ENGINE offering
Several major operators– British Telecom– Vodaphone– Worldcom– Telia– Diveo– ...
2001-03-19 ETX/D/XPS-01:002 Uen 39
Briefly about the term Carrier-Class
To us, "Carrier-Class", "Telephony-Class" and"Telecom Profile" are synonymous
The quality we've come to expectfrom public telephony networks
The trend towards multimedia servicesrequires Carrier-Class in more systems
More than just duplication of hardware:– Fault-tolerant software– In-service hardware expansion– In-service software upgrade– Load tolerance– Flexibility (frequent changes + long service life)
Target: 99,999% ("five nines") availability, including planned outages
There's no such thingas "almost Carrier-Class"!
2001-03-19 ETX/D/XPS-01:002 Uen 40
Optional Processors
Mandatory Mated Processor Pair
ATM
Control Processors
L3F
CE
Switch
Core
FR
ATB
ATB
ATB
ATB
Server Device
LineTermination
ATM Termination
Clock &Synchronization
Clock &Synchronization
IO
IO
IO
IOCP
CP
CP
CP
Device Processoron Each Board
Telecom-Class System Architecturesimple wire-speed logic complex soft-real-time logic
2001-03-19 ETX/D/XPS-01:002 Uen 41
Programming languages (control system)
Erlang: ca 1 million lines of code– Nearly all the complex control logic
– Operation & Maintenance
– Web server and runtime HTML/JavaScript generation
C/C++: ca 500k lines of code– Third party software
– Low-level protocol drivers
– Device drivers
Java: ca 13k lines of code– Operator GUI applets
2001-03-19 ETX/D/XPS-01:002 Uen 42
Experiences from AXD 301 SW Design
Using 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 estimates– Similar line/hour programmer productivity
– 4-10 fewer lines of source code (compared to C/C++, Java, PLEX) 4-10x higher programmer productivity
– Similar number of faults per 1000 lines of source code 4-10x higher quality
2001-03-19 ETX/D/XPS-01:002 Uen 43
Functional Requirements– Use cases (in telecom “traffic cases”)
– User interfaces
– ...
Non-functional Requirements– Code updating without interrupting the service
– Distribution over several processors
– Automatic handover upon error
– Limited restart time
– ...
The non-functional requirements are often much trickier to handle and require technology bottom-up rather than analysis top-down.
2001-03-19 ETX/D/XPS-01:002 Uen 44
Efficient Program Development
Requirements
Ideas
Prototyping
Productification
Interaction with the real environment
Powerful and appropriate abstraction mechanisms
Efficient implementation
Useful tools
2001-03-19 ETX/D/XPS-01:002 Uen 45
A Simple Erlang-XML Document
<?xml version=“1.0”?><home.page title=“My Home Page”>
<title>Welcome to My Home Page
</title><text>
<para>Sorry, this home page is still under construction. Please come back soon!
</para></text>
</home.page>
XML
{‘home.page’, [{title, “My Home Page”}], [{title, “Welcome to My Home Page”}, {text,
[{para, “Sorry, this home page is still under ” “construction. Please come back soon!”}
]}]}.
Erlang
Almost equivalent
2001-03-19 ETX/D/XPS-01:002 Uen 46
Erlang Summary
Declarative– Compact code
Concurrency– Light-weight processes
– Message passing
Soft real-timeRobustness
– Process supervision
– Error trapping
DistributionHot code loadingExternal interfaces
– To hardware and other languages
Portability
www.erlang.orgwww.erlang.se
2001-03-19 ETX/D/XPS-01:002 Uen 47
The Research Continues ...
HiPE - High Performance Erlang (Uppsala, Astec)
ETOS - Erlang to Scheme (Montréal)
Erlang Verification (SICS, Astec)
Type System (Glasgow)
“Safe” Erlang (Canberra)
Specification Techniques (Aachen)
Erlang Processor (Ericsson CADLab)
...