Zurich Erlang 2012
Zurich Erlang 2012
Zurich Erlang 2012
An Introduction to Erlang
From behind the trenches…
@FrancescoC
francesco@erlang-solutions.com
So Here I Am….
Complex
Past Present
Single-service networks Multiservice networks/client server
No down time Content Content
Services
Scalable Control
Communication Media
Maintainable
Cellular
PLMN applications Gateways
CATV Backbone
Network
PSTN/
Distributed ISDN
Data/ IP
Networks
Time to Market
Access transport and switching networks Clients/applications
Logical languages
like Prolog
Declarative
Concurrent Functional programming
language
Robust High abstraction level
Pattern matching
Distributed
Concise readable programs
Hot code loading
Multicore Support
OTP
-module(ex1).
-export([factorial/1]).
1 n=0
n! = factorial(0) ->
1;
n*(n-1)! n≥ 1 factorial(N) when N >= 1 ->
N * factorial(N-1).
qsort([Head|Tail]) ->
First = qsort([X || X <- Tail, X =< Head]),
Last = qsort([Y || Y <- Tail, Y > Head]),
First ++ [Head] ++ Last;
qsort([]) ->
[].
"all objects Y
Eshell V5.0.1 (abort with ^G)
1> c(ex2).
taken from the list
{ok,ex2} Tail, where
2> ex2:qsort([7,5,3,8,1]).
[1,3,5,7,8] Y > Head"
etc…
Declarative
Concurrent Either transparent or
Robust explicit concurrency
Light-weight processes
Distributed Highly scalable
Hot code loading
Multicore Support
OTP
-module(ex3).
-export([activity/3]).
activity(Name,Pos,Size) ->
…………
activity(Joe,75,1024)
Pid = spawn(ex3,activity,[Joe,75,1024])
100
10
Source:
Joe Armstrong
SICS
1
Number of processes 10 100 1,000 10,000 100,000
receive
{start} -> ………
{stop} -> ………
{data,X,Y} -> ………
end
Pid ! {data,12,13}
times java
C#
Microseconds/message
1,000
100
10
1
Source:
Joe Armstrong
SICS
1
Number of processes 10 100 1,000 10,000 100,000
Declarative
Concurrent
Robust
Distributed
Simple and consistent
Hot code loading error recovery
Supervision hierarchies
Multicore Support "Program for the correct case"
OTP
using
spawn_link(…,…,…)
or
link(Pid)
receive
{‘EXIT’,Pid,...} -> ...
end
“Supervisors”
“Workers”
Declarative
Concurrent Explicit or transparent
distribution
Robust Network-aware
Distributed runtime system
B ! Msg
C ! Msg
network
© 2011 – Erlang Solutions Ltd.
Erlang Highlights: Distribution
Simple Remote Procedure Call
loop() ->
receive
{From, {apply, M, F, A}} ->
Answer = apply(M, F, A),
From ! {rex, node(), Answer}
loop();
_Other -> loop()
end.
Declarative
Easily change code in a
Concurrent
running system
Robust Enables non-stop operation
Simplifies testing
Distributed
Hot code loading
Multicore Support
OTP
Version 1 Version 2
Declarative
Concurrent
Robust SMP support provides linear
scalability out of the box
Distributed thanks to its no shared
Hot code loading memory approach to concurrency.
Multicore Support
OTP
migration
Scheduler #2 run queue logic
Chatty
500 processes created
Each process randomly
sends messages and
receives a response
from all other
processes
o res
c
48
x @
0 .4
ca
Declarative
Concurrent
Robust Provides the design patterns,
libraries and tools to develop
Distributed distributed fault tolerant systems.
Hot code loading
Multicore Support
OTP
Applications &
Libraries
System Design
Principles
T
P
© 2011 – Erlang Solutions Ltd.
OTP: System Design Principles
Declarative
Concurrent
Robust
Distributed
Hot code loading
Multicore Support
OTP
Is it Documented?
Is the developer supporting it?
What visibility does support staff have into what is going on?
§ SNMP
§ Live Tracing
§ Audit Trails
§ Statistics
§ CLI / HTTP Interface
How much new code was actually written?
Riak
Distributed, partition tolerant and
scalable database
YAWS
Yet Another Web Server
RabbitMQ
High performance enterprise messaging
Ejabberd
XMPP instant messaging server
1 USA 19,483
2 Sweden 8,465
3 United Kingdom 4,984
4 China 4,897
5 Germany 4,745
6 Russia 4,465
7 France 2,722
8 Canada 2,647
9 India 2,299
10 Japan 2,261
Programming Erlang
§ Software for a Concurrent World
§ by Joe Armstrong
Erlang Programming
§ A Concurrent Approach to Software Development
§ by Francesco Cesarini & Simon Thompson