source: http://g1.computerworld.pl/news/7/4/74432
Description

Erlang/OTP?

(The Open Telecom Platform)

The Erlang Shell

$ erl
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0]
[kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1> A = 2 + 2.
4
2> 

Sprach-Eigenschaften?

Functions as first-class citizens.

Datentypen

Integer
	123456789

Floats
	3.14

Atome 
	januar, februar, true, false

Tupel 
	shape1 = {square, 4}
	shape2 = {circle, 5}

Listen
	Y = ["foo", 9.5, {tuple, tuple}, [1, 2]].
	X = [1, 2, 3].
	"AB" = [65, 66]

Pattern Matching

1> math:fakultaet(3).
6
ok
2>
-module(math).
-export([fakultaet/1]).
		
fakultaet(0) -> 1;
fakultaet(N) -> N * fakultaet(N-1).

Pattern Matching: Binaries

processPacket(<<1:32/big, Rest>>) −> 
	% process packets of type one
	...
;
processPacket(<<2:32/big, Rest>>) −> 
	% process packets of type two
	...
;
httpGET(<<"GET / HTTP/1.1">>) -> ...;

processPacket(<< 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 >>) -> ... ;
Description   Description   Description   Description
Concurrency Distribution Fault-Tolerancy Hot-Code Swapping

What about …?


Semaphoren · Monitore · Synchronization


 

Deadlocks · Race Conditions · Starvation

  • Semaphoren
  • Monitore
  • Synchronization
     
  • Deadlocks
  • Race Conditions
  • Starvation
The world is concurrent. Things in the world don't share data. Things communicate with messages. Things fail.
Joe Armstrong

1) Prozesse

2) Nachrichten

Aktorenmodell

source: http://berb.github.io/diploma-thesis/original/054_actors.html

Processes & Messages

Pid = spawn(Function).

Pid ! Message.
Pid ! {sender, do_task, notifyAll}

Calculator = spawn(calculator).
Calculator ! {self(), increment, 5}.

Receiving Messages

calculator() ->
  receive
    {From, increment, Value} -> From ! Value + 1;

    {From, decrement, Value} -> From ! Value - 1;

    _ -> io:format("unknown operation")
  end.
3> Calculator = spawn(calculator).
4> Calculator ! {self(), increment, 5}.
6
ok
Description   Description   Description   Description
Concurrency Distribution Fault-Tolerancy Hot-Code Swapping

Erlang Node

Lokaler Erlang Node

source: http://berb.github.io/diploma-thesis/original/054_actors.html

Verteilte Erlang-Nodes

source: http://berb.github.io/diploma-thesis/original/054_actors.html

Erlang Nodes

$ erl -name node0 -setcookie "node-group1"

{process1, node1@localhost} ! your_message.
{process1, node1@uni-ulm.de} ! your_message.
Description   Description   Description   Description
Concurrency Distribution Fault-Tolerancy Hot-Code Swapping
7 nines almost unachievable … but we did 9. Why is this? No shared state, plus a sophisticated error recovery model.
Joe Armstrong

Fault tolerance?

Let it fail! Have another process deal with it.

Supervisor Trees

Description
source: http://learnyousomeerlang.com/supervisors
Description   Description   Description   Description
Concurrency Distribution Fault-Tolerancy Hot-Code Swapping

Hot-Code Swapping

2> Service = spawn(ServiceFunction).
3> Service ! {get_price, milk}.
The price of milk is: $0.99

⇒ Editing code
 
4> c(pricing_service).
{ok,pricing_service}
5> Service ! {price, milk}.
The price of milk is: $1.03
source: http://memegenerator.net/instance/33519135
source: http://www.empireonline.com/images/uploaded/indiana-jones-holy-grail.jpg

Take-Away

Sprache Funktional, Pattern Matching
Nebenläufigkeit Leichtgewichtige Prozesse + Asynchrones Message Passing
 
No shared state!
Verteilung Erlang Nodes + Message Passing