Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Slide 1
System Architectures Processes & Server Architecture Communication in a Distributed System Communication Abstractions
Slide 3
A RCHITECTURE
System Architecture:
placement of machines placement of software on machines
Software Architecture:
B UILDING
Slide 2 Two questions:
D ISTRIBUTED S YSTEM
Slide 4
A RCHITECTURE
C LIENT-S ERVER
C LIENT-S ERVER
Request Client
Slide 5
Server Reply
Slide 7
% Client code using the increment server client (Server) -> Server ! {self (), 10}, receive {From, Reply} -> io:format ("Result: ~w~n", [Reply]) end. % Server loop for increment server loop () -> receive {From, Msg} -> From ! {self (), Msg + 1}, loop (); stop -> true end. % Initiate the server start_server() -> spawn (fun () -> loop () end).
Kernel
Kernel
Example client-server code in C: Client-Server from another perspective: client(void) { struct sockaddr_in cin; char buffer[bufsize]; int sd; Slide 8 sd = socket(AF_INET,SOCK_STREAM,0); connect(sd,(void *)&cin,sizeof(cin)); send(sd,buffer,strlen(buffer),0); recv(sd,buffer,bufsize,0); close (sd); }
Client
Slide 6
Server
Request
Reply
Provide service
Time
C LIENT-S ERVER
C LIENT-S ERVER
Request
Slide 9
sd = socket(AF_INET,SOCK_STREAM,0); bind(sd,(struct sockaddr *)&sin,sizeof(sin)); listen(sd, queuesize); while (true) { sd_client = accept(sd,(struct sockaddr *)&cin,&addrlen)); recv(sd_client,buffer,sizeof(buffer),0); DoService(buffer); send(sd_client,buffer,strlen(buffer),0); close (sd_client); } close (sd); }
App. Server
Request Reply
Dbase Server
Kernel
Slide 10
User interface Application Database Application Database Application Database Server machine (a) (b) (c) (d) (e) Database Database
Slide 12
Return data
Time
H ORIZONTAL D ISTRIBUTION
H ORIZONTAL D ISTRIBUTION
Front end handling incoming requests Requests handled in round-robin fashion
Replicated Web servers each containing the same Web pages Disks
P EER
Slide 15
TO
P EER
AND
OVERLAY N ETWORKS
Slide 13
Internet Internet
P EER
request reply
TO
P EER
Peer
Example:
111 000 111 000 111 000 111 000 111 000 111 000 111 000 111 000
Peer
Kernel Kernel
reply request request reply
11 00 11 00 11 00 11 00 11 00 11 00 11 00 11 00
1111111 0000000 1111111 0000000 11111111111111111 00000000000000000 1111111 0000000 11111111111111111 00000000000000000
Peer
1111111 0000000 1111111 0000000 1111111111111111 0000000000000000 1111111 0000000 1111111111111111 0000000000000000
111 000 111 000 111 000 111 000 111 000 111 000 111 000 111 000
1111111 0000000 1111111 0000000 1111111111111111 0000000000000000 1111111 0000000 1111111111111111 0000000000000000
11 00 11 00 11 00 11 00 11 00 11 00 11 00 11 00
Slide 14
request
Peer
reply
Slide 16
111 000 111 000 111 000 111 000 111 000 111 000 111 000 111 000
1111111 0000000 1111111 0000000 11111111111111111 00000000000000000 1111111 0000000 11111111111111111 00000000000000000
11 00 11 00 11 00 11 00 11 00 11 00 11 00 11 00 111 000 111 000 111 000 111 000 111 000 111 000 111 000 111 000
1111111 0000000 1111111 0000000 11111111111111111 00000000000000000 1111111 0000000 11111111111111111 00000000000000000
111 000 111 000 111 000 111 000 111 000 111 000 111 000 111 000
Kernel
1111111 0000000 1111111 0000000 1111111111111111 0000000000000000 1111111 0000000 1111111111111111 0000000000000000
1111111 0000000 1111111 0000000 1111111111111111 0000000000000000 1111111 0000000 1111111111111111 0000000000000000
1111111 0000000 1111111 0000000 1111111111111111 0000000000000000 1111111 0000000 1111111111111111 0000000000000000
U NSTRUCTURED OVERLAY
Edge-server systems
S TRUCTURED OVERLAY
Distributed Hash Table:
Actual node 15 14 13 12 {8,9,10,11,12} {2,3,4} 0 1 {0,1} 2 3
Superpeer Networks:
Regular peers are clients of superpeers Superpeers are servers for regular peers Superpeers are peers among themselves Superpeers may maintain large index, or act as brokers
{13,14,15}
Slide 18
11 10
Slide 20
Regular peers
Nodes have identier and range Data has identier Node is responsible for data that falls in its range Search is routed to appropriate node
Superpeer network
Superpeer
H YBRID A RCHITECTURES
H YBRID A RCHITECTURES
10
S ERVER D ESIGN
Dispatcher thread Request dispatched to a worker thread Server
Worker thread
Slide 21
Slide 23
Operating system
Model
Node 3 Tracker Node 4
Characteristics No parallelism, blocking system calls Parallelism, blocking system calls Parallelism, non-blocking system calls
Edge-Server Networks:
Servers placed at the edge of the network Servers replicate content Mostly used for content and application distribution Content Distribution Networks
Origin server ISPs
S TATEFUL
Stateful:
VS
S TATELESS S ERVERS
Keeps persistent information about clients V Improved performance X Expensive crash recovery X Must track clients
Slide 22
Internet Enterprise networks
Slide 24
Stateless:
Does not keep state of clients soft state design: limited client state V Can change own state without informing clients V No cleanup after crash V Easy to replicate X Increased communication
Replica server
S ERVER D ESIGN
11
C LUSTERED S ERVERS
12
Weak vs Strong Mobility: Slide 27 Weak transfer only code Strong transfer code and execution segment Sender vs Receiver Intitated migration: Sender Send program to compute server
Slide 25
Client requests
Dispatched request
First tier
Second tier
Third tier
R EQUEST S WITCHING
Transport layer switch:
Logically a single TCP connection Response Server
Client
Request
Switch
Slide 26
Server
Slide 28
C OMMUNICATION
DNS-based:
Round-robin DNS
C ODE M OBILITY
13
C OMMUNICATION
14
Shared Memory:
Message Passing:
x=12
i=x
Slide 30
Process A
Process B
Slide 32
Shared memory
Process A
Process B
Address space 1
Address space 2
Address space 1
Address space 2
C OMMUNICATION
15
16
C OMMUNICATION
IN A
D ISTRIBUTED S YSTEM
Previous slides assumed a uniprocessor or a multiprocessor. In a distributed system (multicomputer) things change: Shared Memory: Slide 33
There is no way to physically share memory
C OMMUNICATION M ODES
Slide 35
Data oriented vs control oriented communication Synchronous vs asynchronous communication Transient vs persistent communication
Message Passing:
Over the network Introduces latencies Introduces higher chances of failure Heterogeneity introduces possible incompatibilities
M ESSAGE PASSING
Basics:
send() receive()
Control-oriented communication
Associates a transfer of control with communication Active messages, remote procedure call (RPC) & remote method invocation (RMI)
Variations:
Connection oriented vs Connectionless
Slide 34
Slide 36
Observation:
Hardware and OSes often provide data-oriented communication Higher-level infrastructure often provides control-oriented communication middleware But some OSes provide RPC, MPI provides data-oriented communication
Data Representation:
Marshalling Endianness
C OMMUNICATION M ODES
17
C OMMUNICATION M ODES
18
Combinations:
A A Accepted B Persistent Asynchronous B Persistent Synchronous A Starts processing request Request Received B Transient Synchronous (Receipt Based) Transient Synchronous (Delivery Based) Accepted A Request Received B Transient Synchronous (Response Based) Accepted B Transient Asynchronous A Message can be sent only if B is running
Slide 37
Slide 39
Asynchronous
Sender continues execution after sending message (does not block waiting for reply) Message may be queued if receiver not active Message may be processed later at receivers convenience
Examples?
C OMMUNICATION A BSTRACTIONS
Abstractions above simple message passing make communication easier for the programmer. Slide 40 Provided by higher level APIs
Remote Procedure Call (RPC) & Remote Method Invocation (RMI) Message-Oriented Communication Group Communication Streams
Slide 38
Persistent
Message stored (somewhere) until receiver can accept it Example: email
C OMMUNICATION M ODES
19
20
% Client code using RPC stub client (Server) -> register(server, Server), Result = inc (10), io:format ("Result: ~w~n", [Result]). Slide 43 % RPC stub for the increment server inc (Value) -> server ! {self (), inc, Value}, receive {From, inc, Reply} -> Reply end.
Slide 41
Message-passing details hidden from application Procedure call parameters used to transmit data Client calls local stub which does messaging and marshalling
Confusion of local and remote operations can be dangerous. More on that later...
RPC Implementation:
Client machine Server machine
Example server stub in Erlang: % increment implementation inc (Value) -> Value + 1. % RPC Server dispatch loop server () -> receive {From, inc, Value} -> From ! {self(), inc, inc(Value)} end, server().
Client process
Slide 42
j = inc(i);
2
proc: "inc" int: val(i)
Client stub
Server stub
Slide 44
3
Client OS Message proc: "inc" int: val(i) Server OS
21
22
Parameter marshalling:
stub must pack (marshal) parameters into message structure message data must be pointer free (by-reference data must be passed by-value) may have to perform other conversions:
Sun RPC - interface denition: program DATE_PROG { version DATE_VERS { long BIN_DATE(void) = 1; string STR_DATE(long) = 2; } = 1; } = 0x31234567;
Slide 45
byte order (big endian vs little endian) oating point format dealing with pointers convert everything to standard (network) format, or message indicates format, receiver converts if necessary stubs may be generated automatically from interface specs
Slide 47
/* /* /* /*
Sun RPC - client code: #include <rpc/rpc.h> /* standard RPC include file */ #include "date.h" /* this file is generated by rpcgen */ ... main(int argc, char **argv) { CLIENT *cl; /* RPC handle */ ... cl = clnt_create(argv[1], DATE_PROG, DATE_VERS, "udp"); Slide 48 lresult = bin_date_1(NULL, cl); printf("time on host %s = %ld\n", server, *lresult); sresult = str_date_1(lresult, cl); printf("time on host %s = %s", server, *sresult); clnt_destroy(cl); } /* done with the handle */
Slide 46
XML (data representation) and HTTP (transport) Text-based data stream is easier to debug HTTP simplies integration with web servers and works through rewalls For example, XML-RPC (lightweight) and SOAP (more powerful, but often unnecessarily complex)
23
24
Sun RPC - server code: #include <rpc/rpc.h> #include "date.h" /* standard RPC include file */ /* this file is generated by rpcgen */
Client Call remote procedure Request
A SYNCHRONOUS RPC
Wait for result Return from call Reply Time Server Client Wait for acceptance Return from call Accept request Time
Slide 49
long * bin_date_1() { static long timeval; /* must be static */ long time(); /* Unix function */ timeval = time((long *) 0); return(&timeval); } char ** str_date_1(long *bintime) { static char *ptr; /* must be static */ char *ctime(); /* Unix function */ ptr = ctime(bintime); /* convert to local time */ return(&ptr); /* return the address of pointer */ }
Slide 51
Server
When no reply is required When reply isnt needed immediately (2 asynchronous RPCs deferred synchronous RPC)
The transition from Remote Procedure Call (RPC) to Remote Method Invocation (RMI) is a transition from the server metaphor to the object metaphor. Why is this important? Slide 52
RPC: explicit handling of host identication to determine the destination RMI: addressed to a particular object Objects are rst-class citizens Can pass object references as parameters More natural resource management and error handling But still, only a small evolutionary step
Slide 50
A SYNCHRONOUS RPC
25
26
Slide 53
Slide 55
MPI is BIG. Standard reference has over 100 functions and is over 350 pages long!
MPI primitives:
Slide 54
Transient communication
Slide 56
27
28
Slide 57
Model:
Application-specic queues Messages addressed to specic queues Only guarantee delivery to queue. Not when. Message transfer can be in the order of minutes
Slide 59
Component
Event bus
Very similar to email but more general purpose (i.e., enables communication between applications and not just people)
Slide 58
Slide 60
29
30
Used for:
Replication of services Replication of data Service discovery
S TREAMS
Slide 63
Support for Continuous Media Between applications Between devices
Slide 61
Event notication
Issues:
Reliability Ordering
Example:
IP multicast Flooding
Slide 62
Slide 64
S TREAMS
31
S TREAMS
32
Data Streams:
Sequence of data units Can apply to discrete and continuos media (e.g., TCP connection is a stream) Simple stream: single sequence of data Complex stream: several related streams (substreams) (e.g., audio and video)
Stream Synchronisation: Maintaining temporal relationships between substreams Examples: synchronised audio and video, stereo audio Client based
Client receives multiple streams
Transmission modes: Slide 65 Asynchronous no timing constraints (e.g., le transfer) Synchronous maximum end-to-end delay for each data unit (e.g., sending sampled data. Must not be too old when it reaches destination) Isochronous maximum and minimum end-to-end delay (e.g., video) Will concentrate on Isochronous streams Slide 67
Uses synchronisation prole to synchronise Example: based on timestamps X Different streams may have different delays
Server based
Multiplex data streams into one stream X Whats the problem with this?
R EADING L IST
Application
Slide 66
Slide 68
Implementing Remote Procedure Calls A classic paper about the design and implementation of one of the rst RPC systems.
Regular stream
S TREAMS
33
R EADING L IST
34