Erlang Overview

Document Sample
Erlang Overview Powered By Docstoc
					Erlang Open Telecom Platform

EAB/UPD/S Ulf Wiger

Rev PA1

2003-12-01

1

Contents
• • • • • Background The Erlang Language OTP The Erlang/OTP Test Server Experiences

Rev PA1

2003-12-01

2

History of Erlang
How to design SW for future telecoms systems?
1987: Early Erlang Prototype projects 1995: Several new projects

1998: Open Source Erlang

1984-86: Experiments programming POTS with several languages

1993: Distributed Erlang

1996: Open Telecom Platform AXD and GPRS started

1991: First fast implementation

Rev PA1

2003-12-01

3

Downloads since Open Source Launch ’98
180000 160000

140000

120000 Windows Unix Total (just OTP) OTP+Wings Overall Linear (Total (just OTP))

100000

80000

60000

40000

20000

0
1999Q1-2 1999Q3-4 2000Q1-2 2000Q3-4 2001Q1-2 2001Q3-4 2002Q1-2 2002Q3-4 2003Q1-2 2003Q3-4 2004Q1-2

Grouping: 6 months

Rev PA1

2003-12-01

4

Erlang-based Products as of today
• Ericsson: AXD 301, GPRS, (NetSim), LCS • Nortel: SSL Accelerator, SSL VPN gateway + others • TMobile: IN applications • Vail Systems: Computer Telephony Apps Service Prov. • Erlang Financial Systems: Banking & Lottery systems • Mobile Arts: Presence & Messaging for GSM/UMTS
Rev PA1 2003-12-01

• Synap.se: Billing & device configuration • Blue Position: Bluetooth Location Information System • Motivity: Answer Supervision Generator, Signalling Gateway • Telia: CTI Platform • Corelatus: Signalling gateways & cross-connects • Bluetail/TeleNordia: Robust SMTP Mail Server • Univ. of Coruña: VoD Cluster
5

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability
Functional programming language High abstraction level Pattern matching Concise readable programs

Rev PA1

2003-12-01

6

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability
Solid concurrency model Scales to handle complex concurrency Simple abstractions

Examples...

Rev PA1

2003-12-01

7

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)

Rev PA1

2003-12-01

8

Erlang Example
Processes communicate by asynchronous message passing

Pid ! {data,12,13}

receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ……… end
2003-12-01 9

Rev PA1

Erlang Examples 4
Concurrency - Finite State Machine
ringing_B_side(PidA) -> Selective receive receive {lim, offhook} -> lim:stop_ringing(), True encapsulation PidA ! {hc, {connect, self()}}, of sub-states speech(PidA); {hc, {cancel, PidA}} -> cancel(PidA); Asynchronous {lim, {digit, _Digit}} -> ringing_B_side(PidA); send {hc, {request_connection, Pid}} -> Pid ! {hc, {reject, self()}}, ringing_B_side(PidA) after 30000 -> cancel(PidA) Optional timeout end.

Rev PA1

2003-12-01

10

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability
Lightweight processes Fast message passing Response times in the order of milliseconds efficient garbage collection

Numbers...

Rev PA1

2003-12-01

11

Process creation times (LOG/LOG scale)
1,000

erlang java C# Microseconds/process

100

10

Source: Joe Armstrong SICS

> 200,000 processes

1
10 100 1,000 Number of processes
Rev PA1 2003-12-01 12

10,000

100,000

Message passing times (LOG/LOG scale)
100,000

erlang java
10,000

C#

Microseconds/message

1,000

100

10 Source: Joe Armstrong SICS

1

> 200,000 processes

1 10 100 1,000 Number of processes
Rev PA1 2003-12-01 13

10,000

100,000

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability
Simple and consistent error recovery Supervision hierarchies "Program for the correct case"

Examples...

Rev PA1

2003-12-01

14

Erlang Example
Cooperating processes may be linked together

using
spawn_link(…,…,…)

or
link(Pid)
Rev PA1 2003-12-01 15

Erlang Example
When a process terminates, an exit signal is sent to all linked processes

… and the termination is propagated
Rev PA1 2003-12-01 16

Erlang Example
Exit signals can be trapped and received as messages

process_flag(trap_exit,true), ... receive {‘EXIT’,Pid,...} -> ... end
Rev PA1 2003-12-01 17

Erlang Example
Robust systems can be built by layering

“Supervisors”

“Workers”

Rev PA1

2003-12-01

18

Error-handling -- Language Safety
• • • • No global variables -- fewer side-effects No direct memory access -- no pointer errors No malloc/free bugs Solid concurrency model -- reduces synchronization problems, reduces the state space (simpler programs) • Fault isolation -- memory-protected lightweight processes • Built-in error recovery support -- more consistency
Concurrency & Fault Tolerance were designed into the language from the start!
Rev PA1 2003-12-01 19

Debugging and Profiling Support
• Symbolic crash reports
– Usually sufficient info to locate bugs within minutes

• Built-in trace support
– – – – – – – Function calls (ability to filter on module name, function and args) Messages (+ sequence trace) Process events (context switch, spawn, link, exit) Garbage collections Optionally with timestamps (can be used for profiling, benchmarks) Trace to process, file, or port (network socket) Also available on live systems
2003-12-01 20

Rev PA1

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability

Explicit or transparent distribution Network-aware runtime system

Examples...

Rev PA1

2003-12-01

21

Transparent Distribution

B ! Msg C ! Msg
Erlang Run-Time System

Erlang Run-Time System

network
Message passing between processes in different computer is just as easy as between processes in the same computer
Rev PA1 2003-12-01 22

Simple RPC
{rex, Node} ! {self(), {apply, M, F, A}}, receive {rex, Node, What} -> What end

loop() -> receive {From, {apply, M, F, A}} -> Answer = (catch apply(M, F, A)), From ! {rex, node(), Answer} loop(); _Other -> loop() end.

Rev PA1

2003-12-01

23

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability
Easily change code in a running system Enables non-stop operation Simplifies testing

Examples...

Rev PA1

2003-12-01

24

Erlang Example
change_code

Version 1

Version 2

Rev PA1

2003-12-01

25

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability

"Ports" to the outside world behave as Erlang processes (c.f. UML ports)

Examples...

Rev PA1

2003-12-01

26

Erlang Example

Port

External process

Port ! {self(), {command, [1,2,3]}}

Rev PA1

2003-12-01

27

Erlang Example

A port can use e.g. a TCP, UDP, SSL socket, UNIX pipe, or custom transport (e.g. SAAL)

Port

External process

receive {Port, {data, Info}} -> end
Rev PA1 2003-12-01 28

Erlang Highlights
• • • • • • • • Declarative Concurrency Soft real-time Robustness Distribution Hot code loading External interfaces Portability Erlang runs on any UNIX, Windows, VxWorks, OSE Delta Supports heterogeneous networks

Illustration...

Rev PA1

2003-12-01

29

Systems Overview
Applications written in Erlang
Applications written in C, C++ or Java

OTP Components

Standard Libraries Erlang Run-Time System

Hardware and Operating System

Rev PA1

2003-12-01

30

Erlang/OTP (Open Telecom Platform)
• • • • Middleware for Erlang development Designed for fault tolerance and portability Behaviors: A formalization of design patterns Components
– – – – – – – – Error handling, reporting and logging Mnesia, distributed real-time database management system CORBA, IDL Compiler, Java & C Interface Support HTTP Server + Client, FTP Client SNMP Agent + ASN.1 Compiler H.248 XML ...
2003-12-01 31

Rev PA1

OTP Behaviors
• "A formalization of design patterns"
– A framework + generic code to solve a common problem – Built-in support for debugging and software upgrade – Makes it easier to reason about the behavior of a program

• Examples of OTP behaviors
– – – – – application supervisor gen_server gen_event gen_fsm defines how an application is implemented used to write fault-tolerant supervision trees for writing client-server applications for writing event handlers for finite state machine programming
2003-12-01 32

Rev PA1

Principles of the OTP Test Server
Erlang VM

Test suite Test server library Adaptation library

erl erl erl Application being tested Application being tested

Erlang rpc, "socket rpc", Corba, ...

erl

Corba, SNMP, ... Application being tested

Rev PA1

2003-12-01

33

Experiences from Erlang in Large Projects
• • • • • • • • • Easy to build a first runnable application Easy to debug Easy to maintain Very strong support for fault tolerance Suitable for large systems/projects Great for prototyping Impressive performance/scalability in real applications Outstanding tool for test automation High programmer satisfaction
Rev PA1 2003-12-01 35

Questions?

Rev PA1

2003-12-01

36


				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:81
posted:1/17/2010
language:English
pages:35