distributed systems - fall 2013 - kocwelearning.kocw.net/contents4/document/lec/2013/gachon/you...

32
COMMUNICATION Joon Yoo Dept. of Software Design & Management Gachon University Distributed Systems - Fall 2013

Upload: others

Post on 27-Mar-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

COMMUNICATION

Joon Yoo

Dept. of Software Design & ManagementGachon University

Distributed Systems - Fall 2013

Page 2: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Communications

o Fundamentals

o Remote Procedure Call

o Message-Oriented Communication

- 2Distributed Systems - Fall 2013

Page 3: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

4.1. Fundamentals

o Layered Protocols

n Lower-Level Protocols

n Transport Protocols

n Higher-Level Protocols

n Middleware Protocols

o Types of Communication

- 3Distributed Systems - Fall 2013

Page 4: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Layered Protocols

o Shared Memory? – SMP system

o No-shared Memory – Distributed Computing (System)n So how do we communicate? – By sending and receiving

messages

n Process A wants to communicate with process B– Process A builds message on its own address space

– Executes system call that causes OS to send message over the network to B

– A and B has to agree on the meaning of bits being sent

n A sends a ‘Chinese novel’ while B only speaks English – Less than optimal

n A sends a ‘French novel encoded in IBM’s EBCDIC code’ while B expects English encoded in ASCII format – Less than optimal

– Make them agree on the same language! → Layered Protocol

- 4Distributed Systems - Fall 2013

Page 5: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Layered Protocols

o Many different agreements need to be maden How does the receiver know which is the last bit of the

message?

n How can it detect if message has been damaged or lost, and what should it do if it finds out?

n How long are numbers, strings, and other items, and how are they represented?

o Agreements are needed in various levelsn Low level: Lower layers might handle things like how to

turn electrical voltages into 1s and 0s.n High level: How information is expressed. You don’t want to

be dealing with voltage when implementing the HTTP protocol.

- 5Distributed Systems - Fall 2013

Page 6: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

o Protocols are formal set of rules that govern the format, contents, and meaning of the messages send and received.

o Connection oriented and connectionless protocols.n Connection oriented does some initial work to set up a

“virtual circuit”. Connectionless does not.n Examples?

– Phone is connection-oriented.– Mail is connectionless.

n Pros and cons– Connection-oriented are usually more reliable and robust.– Connectionless are usually more simple.

- 6

Two general types of protocols

Distributed Systems - Fall 2013

Page 7: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Layered Protocols

o Each layer has its own protocol that can be changed independently of the other one.

o Example of changing a layer without affecting other layers

n Physical Layer can change from 10Mbps Ethernet to 1Gbps Ethernet (or IEEE 802.11n Wi-Fi) without changing Transport and Network (TCP/IP) Layers

n Network Layer can change from IPv4 to IPv6 without changing physical layer that uses Giga-bit Ethernet.

- 7Distributed Systems - Fall 2013

Page 8: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Physical Layer (1/2)

o Transmitting 0s and 1so How many volts to use for 0 and 1, how many bits

per second can be sent, what is the transmission media…

o Examples: n IEEE 802.2 Ethernetn IEEE 802.11 WLAN (Wi-Fi)

– 2.4GHz band, OFDM, BPSK/QPSK/16QAM modulation…

o Physical Layer just sends bits – all is well if there are no errors

o But, real communication networks (especially wireless) are subject to errorsn We need a mechanism that detects and corrects errorsn Solution: Data Link Layer

- 8Distributed Systems - Fall 2013

Page 9: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Physical Layer (2/2)

- 9

011001100…0011

- What frequency MHz- What MBps…

Distributed Systems - Fall 2013

Page 10: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Data Link Layer (1/2)

o Group the bits into a unit called frames (≈ packet).

o Physical layers are unreliable. Main job of this layer is to detect and correct errors. How?n One method: Checksum

- 10

011001…100011 100011…001011 … 110010…100011

Frames

Data

Distributed Systems - Fall 2013

Page 11: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Data Link Layer (2/2)

o On a LAN there is no need for the sender to locate the receiver

n Sender just puts the message on the network (Ethernet BUS, switch, etc) and receiver gets it

o On a WAN, with a large number of machines, and large-scale map

n There may be many paths, and a number of hops (networks in-between paths) from sender to receiver

n Network Layer

– Choosing the best path – IP Routing

– Identifying the receiver – IP address

- 11Distributed Systems - Fall 2013

Page 12: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Transport Layer (1/3)

o The transport layer provides the actual communication facilities for most distributed systems.

o Standard Internet protocols:n Transmission Control Protocol (TCP)

– Connection-oriented, reliable

– web, E-mail, file transfer

n Universal Datagram Protocol (UDP)– Unreliable (best-effort) datagram communication

– real-time applications (voice, video…)

- 12Distributed Systems - Fall 2013

Page 13: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Transport Layer (2/3)

o Real-time Transport Protocol (RTP/UDP)n On top of UDP

n For semi-connection oriented for Real-time applications

o HTTP Adaptive Streaming (HAS)n Adobe Flash Player, MS Silverlight/Windows Phone 7,

Apple QuickTime for iPhone/iPad

n Use HTTP/TCP for real-time streaming

n Somewhat of a middleware (between Transport and Application)

n can leverage the HTTP servers used for Web services –no need for specialized streaming server infrastructure.

- 13Distributed Systems - Fall 2013

Page 14: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

o Session, Presentation layer → merged to Application layer

o Application layer

n Application specific protocols for like mail, file transfer, communication terminals.

n Examples: FTP (File Transfer Protocol), HTTP (HyperTextTransfer Protocol)

o General-purpose protocols are useful to many applications (not just one application)

n These are categorized as middleware protocols

- 14

Higher-level Layers

Distributed Systems - Fall 2013

Page 15: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Middleware Protocols

o Observation: Middleware logically at application layer, but provides common services and protocols that can be used by many different applications.n A rich set communication protocols to allow different

apps. to communicate – Remote Procedure Call (RPC)n Naming protocols, so that different apps. can easily share

resourcesn Security protocols, to allow different apps. to

communicate in a secure way – authentication, authorizationn Sharing mechanisms, control access to shared resources

to protect against simultaneous access

- 15Distributed Systems - Fall 2013

Page 16: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Type of Communications (2/4)

o Transient Communication

n Message can be submitted only when sending and receiving application are executing (active) – FTP application

n If receiver is not active then message will be discarded

n Typically all transport-level communication services– If TCP cannot deliver the packet now, then it will drop the packet.

o Persistent vs. Transient Communicationn Persistent communication: A message is stored at a

communication server (middleware) as long as it takes to deliver it at the receiver.

n Transient communication: A message is discarded by a communication server (middleware) as soon as it cannot be delivered at the next server, or at the receiver.

- 16Distributed Systems - Fall 2013

Page 17: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Type of Communications (4/4)o Message-queuing systemsn Persistence in combination with synchronization at

request submission

o Remote Procedure Calls (RPCs)n Transient communication with synchronization after the

request has been fully processed

o Discrete vs. Streaming communicationn Discrete

– The parties communicate by messages. All of the above are discrete.

n Streaming communication– Involves sending multiple message, one after the other, where the message

are related to each other by the order they are sent

- 17Distributed Systems - Fall 2013

Page 18: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Client/Server

o Some observations: Client/Server computing is generally based on a model of transient synchronous communication:n Client and server have to be active at the time of

communicationn Client issues request and blocks until it receives replyn Server essentially waits only for incoming requests, and

subsequently processes them

o Drawbacks synchronous communication:n Client cannot do any other work while waiting for replyn Failures have to be dealt with immediately (the client is

waiting)n In many cases the model is simply not appropriate (mail,

news)

- 18Distributed Systems - Fall 2013

Page 19: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

4.2 Remote Procedure Call

- 19

o Basic RPC Operation

o Parameter Passing

o Variations

Distributed Systems - Fall 2013

Page 20: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Communication in Distributed Systems

o Explicit message exchange between processes on different machines

n Use send and receive procedures

n Does not conceal communication - cannot achieve access transparency

o Allow programs to call procedures located on other machines

n Remote Procedure Call (or RPC)

- 20Distributed Systems - Fall 2013

Page 21: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Call Methods

o Call-by-value

n fd and nbytes

o Call-by-reference

n buf

o Call-by-copy/restore

n Under most conditions, same effect as call-by-reference

n But in some situations, such as the same parameter being present multiple times in the parameter list, the semantics are different (next slide example)

n Used for RPC

- 21Distributed Systems - Fall 2013

Page 22: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

22/N

Example 1.1

void foo(int x, int y){x = 7;y = y + 2; }

int main(){int j = 3;foo(j, j);print(j); }

Under call by-reference:•x refers to j•y refers to j•j is assigned the value of 7 through x•j is assigned the value of 7+2 = 9 through y•after the function returns, 9 is printed as the value of j

Under call by copy-restore:•x is assigned the value of j = 3•y is assigned the value of j = 3•the address location of j is stored as the copy-out address for both x and y•x is assigned the value of 7•y is assigned the value of 3+2 = 5•the value of x = 7 is copied out to j•the value of y = 5 is copied out to j, thus overwriting 7•after the function returns, 5 is printed as the value of j

Distributed Systems - Fall 2013

Page 23: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

RPC Operation - Client stubo Example: Read some data from file on different

machinen Now, read is a remote procedure (e.g., running on file server’s

machine)n Different version of read, called client stub, is put into the

libraryn Client stub is a piece of code that transforms local procedure

calls into requests to be sent over the networkn Same as before, use calling sequence by calling the local OSn Unlike before, client stub packs the parameters into a

message and request that message to be sent to the servern Following the call to send, the client stub calls receive, blocking

itself until the reply comes back

- 23Distributed Systems - Fall 2013

Page 24: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

RPC operation – Server stub

o When message arrives at servern Server’s OS passes message to server stub (equivalent to a

client stub).

n Server stub is a piece of code that transforms requests coming in over the network into local procedure calls

n receive is used to be blocked and wait for incoming messages

n Unpacks parameters from message then calls server procedure in normal way – server thinks this is called directly by the client (not by remote machine)

n Server performs its work and then returns the result to caller (e.g., in case for read, sever will fill the buffer with data. Here, the buffer is internal to the server stub)

n Packs the result in a message and calls send to return it to client

- 24Distributed Systems - Fall 2013

Page 25: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

RPC operation – Client stub again

o When message gets back to client machine

n Client’s OS sees that message is addressed to client process (client stub)

n Client process (stub) is unblocked (it was using receive)

n Client stub inspects the message, unpacks the result and copies it to its caller, and returns in the usual way

- 25Distributed Systems - Fall 2013

Page 26: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Remote Procedure Call

o Turn a normal looking procedure calla = my_func(i, x);

and make it happen on a remote machine.o What needs to happen?n Pack parameters and other information into a

message (marshalling)n Send message to process on remote machine.n Unpack message on remote machine

(unmarshalling).n Call the appropriate remote procedure, locally.n Get the return value, send back.

- 26Distributed Systems - Fall 2013

Page 27: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Stubs

o Client stubn Piece of code responsible for proxying the remote

call as a local call, and packaging the call up as a message.

o Server stubn Piece of code responsible for unpacking the message

on the server, and invoking the actual server-side, application-level implementation.

- 27Distributed Systems - Fall 2013

Page 28: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Passing Value Parameters

o If client/server machines are identical and all parameters and results are scalar types, this model works fine

o In distributed systems, multiple machine types can commonly be present

n For character: IBM mainframe server uses EBCDIC character code, IBM PC uses ASCII

n For integer: Intel Pentium uses little endian (number bytes from right to left), Motorola uses big endian (number bytes from left to right)

- 28Distributed Systems - Fall 2013

Page 29: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Passing Reference Parameters

o How about reference parameters, or pointers?n Client and Server has different address space of the process

n How can you send reference (pointer) parameters?– Only with greatest difficulty, if at all.

n Can use copy/restore.

n Suppose there is a 500 size integer array being passed:– int a[500];

remote_call(a, 500);– This would copy the array into the message, send it over, the array would be

sent back, and then the contents of the message would be copied back over the original array.

– Efficient? How about structures? How about pointer to complex graphs?

o In summary, both sides in an RPC should follow the same protocol; agree on data structure representation and communication type.

- 29Distributed Systems - Fall 2013

Page 30: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Asynchronous RPC

o For example,n Client may want to prefetch network addresses of a set of

hosts

n While naming service is collecting those addresses client may want to do other things

o Two asynchronous RPCsn Client calls server to fetch list of host names

n Client continues when the server calls the client to tell the receipt of that list

n This is called deferred synchronous RPC

- 30Distributed Systems - Fall 2013

Page 31: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Binding a Client to a Server

o Registration of a server makes it possible for a client to locate the server and bind to it.

o Client-Server binding procedure1. Server registers end point (or port) to DCE daemon (A

table of (server, end point))

2. Server registers with directory service by providing network address

3. Client look up server to locate the server’s machine

4. Client asks for server end point

5. Do RPC

- 31Distributed Systems - Fall 2013

Page 32: Distributed Systems - Fall 2013 - KOCWelearning.kocw.net/contents4/document/lec/2013/Gachon/You Jun/7.pdf · Distributed Systems - Fall 2013. Communications oFundamentals oRemote

Is RPC always good?

o Recall the advantages of RPCn Hide communication (send, receive) in distributed systems

(i.e., enhance access transparency).

o RPC is transient/synchronous communicationn Receiving side is executing at the time of a request

n Client is blocked until its request has been processed

o How do we solve this problem?n Messaging-Queuing Model

- 32Distributed Systems - Fall 2013