Introduction To Distributed Erlang
Click here to load reader
-
Upload
david-dossot -
Category
Technology
-
view
3.876 -
download
7
Transcript of Introduction To Distributed Erlang
Introduction to Distributed Erlang
Basic principles and a little more
About us
Developing a new breed of platform for social networking gamesScalability is a must Back-end developed with Erlang/OTP
And lots of other good stuffFront-end developed with Flex 4
Agenda and non-agenda
Quick recap of message passingCore principles of Erlang remotingGlobal registry and process groupsNothing on Erlang syntax {<<"sorry">>}Nothing on custom networking nor OTP
OTP is what you'll use in reality
Why Erlang for concurrency?
Immutability painted all over itDesigned to handle thousands of processes
Spawned (not started nor forked)Processes communicate asynchronouslyPassing messages by value
Message sending
As easy as:
Pid ! MessageSends a message to a process inboxLike with mail delivery:
Not sure if the letter reached its destinationNeeds a letter back if a response is needed
RSVP
Add address on the envelope for a response
RSVP (client)
send(Sid, Message) -> Sid!{self(), Message}, receive {From, Response} -> io:format("Client ~p from ~p~n", [Response, From]) after 1000 -> bail end.
Client is also Server's public
API
RSVP (server)
start() -> spawn(fun()-> serve() end).serve() -> receive {From, Message} -> io:format("Server ~p from ~p~n", [Message, From]), From!{self(), {ack, Message}}, serve() end.
Process registration
Allows process naming:
register(my_pid, Pid).Frees application from passing Pids around:
my_pid ! Message.
RPC strikes back
Call MFA on single or multiple nodesDeclined in zillions of variations:
Blocking or notParallelized, including pmap
Makes code location awareHeterogeneous styles:
Pid ! Message rpc:call(N,M,F,A)
Node connectivity
Triggered by:
rpc:call ...net_adm:ping(node@host)Nodes shake hands and share information
Processes, registrations...Transitive mechanism
Node 1 ➟ Node 2 and Node 2 ➟ Node3then: Node 1 ➟ Node 3
Erlang Port Mapper Daemon
Erlang's magic cookie
Passed on startup:
erl -sname n1 -setcookie=secretProper node and host naming requiredCoarse grained security
Party time or bust!
Global process registry
Location transparency:
global:register_name(gbs, Sid).global:whereis_name(gbs) ! Message.Wired-in name conflict resolutionStill need to ping nodes
Process group (1/3)
Distributed named process group Processes join and leave:
pg2:create(mypg2).
pg2:join(mypg2, Sid).
pg2:leave(mypg2, Sid).
Process group (2/3)
pg2 can be used to send messages to:all processes:
pg2:get_members(mypg2)local processes:
pg2:get_local_members(mypg2)closest / random process:
pg2:get_closest_pid(mypg2)
Process group (3/3)
Also: pg (experimental)
Ping pong pang relief
net_adm:world and net_adm:world_listEase node discovery on hostsRequires hosts list
Node discovery with nodefinderUDP multicast S3 list for AWS
Probing further
Thank you!