37
Distributed Computing, M. L. Liu 1 Interprocess Communications Mei-Ling L. Liu

Interprocess Communications - UVa

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Interprocess Communications - UVa

Distributed Computing, M. L. Liu1

Interprocess Communications

Mei-Ling L. Liu

Page 2: Interprocess Communications - UVa

Distributed Computing, M. L. Liu2

Interprocess Communications

- Operating systems provide facilities for interprocesscommunications (IPC), such as message queues, semaphores, and shared memory.

- Distributed computing systems make use of these facilities to provide application programming interface which allows IPC to be programmed at a higher level of abstraction.

- Distributed computing requires information to be exchanged among independent processes.

Page 3: Interprocess Communications - UVa

Distributed Computing, M. L. Liu3

IPC – unicast and multicast

In distributed computing, two or more processes engage in IPC in a protocol agreed upon by the processes. A process may be a sender at some points during a protocol, a receiver at other points. When communication is from one process to a single other process, the IPC is said to be a unicast. When communication is from one process to a group of processes, the IPC is said to be a multicast, a topic that we will explore in a later chapter.

Page 4: Interprocess Communications - UVa

Distributed Computing, M. L. Liu4

Unicast vs. Multicast

P2

P1 P1

P2 P3 P4...

unicast multicast

m m m m

Page 5: Interprocess Communications - UVa

Distributed Computing, M. L. Liu5

Process 1 Process 2

data

sender receiver

Interprocess Communications in Distributed Computing

Page 6: Interprocess Communications - UVa

Distributed Computing, M. L. Liu6

Operations provided in an archetypal Interprocess Communications API

• Receive ( [sender], message storage object)• Connect (sender address, receiver address), for

connection-oriented communication.• Send ( [receiver], message)• Disconnect (connection identifier), for connection-

oriented communication.

Page 7: Interprocess Communications - UVa

Distributed Computing, M. L. Liu7

Interprocess Communication in basic HTTP

C1 C2

S3 S4

C4

Web server

Web browser

a process

an operation

data flow

operations:S1: accept connectionS2: rece ive (request)S3: send (response)S3: disconnectC1: make connectionC2: send (request)C3: rece ive (response)C4: disconnect

S2

C3

S1

HTTPrequest

HTTPresponse

Page 8: Interprocess Communications - UVa

Distributed Computing, M. L. Liu8

Event Synchronization

Interprocess communication requires that the two processes synchronize their operations: one side sends, then the other receives until all data has been sent and received.Ideally, the send operation starts before the receive operation commences.In practice, the synchronization requires system support.

Page 9: Interprocess Communications - UVa

Distributed Computing, M. L. Liu9

Synchronous vs. Asynchronous Communication

The IPC operations may provide the synchronization necessary using blocking. A blocking operation issued by a process will block further processing of the process until the operation is fulfilled.Alternatively, IPC operations may be asynchronous or nonblocking. An asynchronous operation issued by a process will not block further processing of the process. Instead, the process is free to proceed with its processing, and may optionally be notified by the system when the operation is fulfilled.

Page 10: Interprocess Communications - UVa

Distributed Computing, M. L. Liu10

Synchronous send and receive

process 1running on host 1

blocking send starts

blocking send returns

blocking receive starts

blocking receive ends

execution flow

suspended period

Synchronous Send and Receive

an operation

acknowledgement of data receivedprovided by the IPC facility

process 2running on host 2

Page 11: Interprocess Communications - UVa

Distributed Computing, M. L. Liu11

Asynchronous send and synchronous receive

Process 1Process 2

blocking receive starts

blocking receive returns

execution flow

suspended period

Asynchronous Send and Synchronous Receive

nonblocking send

operation

Page 12: Interprocess Communications - UVa

Distributed Computing, M. L. Liu12

Synchronous send and Async. Receive - 1

Process 1Process 2

nonblocking receive issuedexecution flow

suspended period

Synchronous Send and Asynchronous Receive

blocking send issued

Scenario A

transparent acknowledgementprovided by the IPC facility

Page 13: Interprocess Communications - UVa

Distributed Computing, M. L. Liu13

Synchronous send and Async. Receive - 2

indefiniteblocking

Process 1Process 2

nonblocking receive issuedand returned immediately

execution flow

suspended period

Synchronous Send and Asynchronous Receive

blocking send issued

Scenario B

Process 1Process 2

Page 14: Interprocess Communications - UVa

Distributed Computing, M. L. Liu14

Synchronous send and Async. Receive - 3

Process 1Process 2

nonblocking receive issuedand returned immediately

execution flow

suspended period

Synchronous Send and Asynchronous Receive

blocking send issued

Scenario C

process is notifiedof the arrival ofdata

transparent acknowledgementprovided by the IPC facility

Page 15: Interprocess Communications - UVa

Distributed Computing, M. L. Liu15

Asynchronous send and Asynchronous receive

Process 1Process 2

nonblocking receive issuedand returned immediately

execution flow

suspended period

Asynchronous Send andAsynchronous Receive

Non blocking send issued

Scenario C

process is notifiedof the arrival ofdata

Page 16: Interprocess Communications - UVa

Distributed Computing, M. L. Liu16

Event diagram

Process AProcess B

interprocess communication

execution flow

process blocked

Event diagram for a protocol

request 1

response 1

response2

request 2

time

Page 17: Interprocess Communications - UVa

Distributed Computing, M. L. Liu17

Blocking, deadlock, and timeouts

Blocking operations issued in the wrong sequence can cause deadlocks.Deadlocks should be avoided. Alternatively, timeout can be used to detect deadlocks.

receive from process 2 issued

received from process 1 issued

process 1 blocked pending datafrom process 2.

process 2 blocked pending datafrom process 1.

Process 1 Process 2

Page 18: Interprocess Communications - UVa

Distributed Computing, M. L. Liu18

Using threads for asynchronous IPCWhen using an IPC programming interface, it is important to notewhether the operations are synchronous or asynchronous. If only blocking operation is provided for send and/or receive, then it is the programmer’s responsibility to using child processes or threads if asynchronous operations are desired.

process

main thread

new thread issues a blocking IPC operation

thread is blocked

thread is unblocked after the operation is fulfilled

main thread continues withother processing

Page 19: Interprocess Communications - UVa

Distributed Computing, M. L. Liu19

Deadlocks and Timeouts

Connect and receive operations can result in indefinite blockingFor example, a blocking connect request can result in the requesting process to be suspended indefinitely if the connection is unfulfilled or cannot be fulfilled, perhaps as a result of a breakdown in the network .It is generally unacceptable for a requesting process to “hang” indefinitely. Indefinite blocking can be avoided by using timeout. Indefinite blocking may also be caused by a deadlock

Page 20: Interprocess Communications - UVa

Distributed Computing, M. L. Liu20

Indefinite blocking due to a deadlock

"receive from process 2" issued;

"receive from process 1" issued;

process 1 blocked pending datafrom process 2.

process 2 blocked pending datafrom process 1.

Process 1 Process 2

processexecuting

processblocked

an operation

Page 21: Interprocess Communications - UVa

Distributed Computing, M. L. Liu21

Data Representation

Data transmitted on the network is a binary stream.An interprocess communication system may provide the capability to allow data representation to be imposed on the raw data.Because different computers may have different internal storage format for the same data type, an external representation of data may be necessary.Data marshalling is the process of (I) flatterning a data structure, and (ii) converting the data to an external representation.Some well known external data representation schemes are:

Sun XDRASN.1 (Abstract Syntax Notation)XML (Extensible Markup Language)

Page 22: Interprocess Communications - UVa

Distributed Computing, M. L. Liu22

Data Encoding Protocols

application specific data encoding language

general data encoding language

network data encoding standard

data encoding schemes Sample Standardslevel of abstraction

XML:(Extensible Markup Language)

ASN.1(Abstract Syntax Notation)

Sun XDR(External Data Representation)

Page 23: Interprocess Communications - UVa

Distributed Computing, M. L. Liu23

Sample XML filehttp://java.sun.com/xml/docs/tutorial/overview/1_xml.html#intro

XML is a text-based markup language that is fast becoming the standard for data interchange on the Web. XML has syntax analogus to HTML.Unlike HTML, XML tags tell you what the data means, rather than how to display it.Example:<message>

<to>[email protected]</to><from>[email protected]</from><subject>XML Is Really Cool</subject><text> How many ways is XML cool? Let me count the ways... </text>

</message>

Page 24: Interprocess Communications - UVa

Distributed Computing, M. L. Liu24

Data Marshalling

"This is a test."

"This is a test."

1.2 7.3 -1.5

1.2

7.3

-1.5

110011 ... 10000100 ...

marshalling

unmarshalling

1. flattening of structured data items2. converting data to external (network) representation

1. convert data to internal representation2. rebuild data structures.

host A

host B

External to internal representation and vice versais not required - if the two sides are of the same host type; - if the two sides negotiates at connection.

Page 25: Interprocess Communications - UVa

Distributed Computing, M. L. Liu25

Text-based protocols

Data marshalling is at its simplest when the data exchanged is a stream of characters, or text. Exchanging data in text has the additional advantage that the data can be easily parsed in a program and displayed for human perusal. Hence it is a popular practice for protocols to exchange requests and responses in the form of character-strings. Such protocols are said to be text-based. Many popular network protocols, including FTP (File

Transfer Protocol), HTTP, and SMTP (Simple Mail Transfer Protocol), are text-based.

Page 26: Interprocess Communications - UVa

Distributed Computing, M. L. Liu26

Event diagram for a protocol session

Process 1Process 2

interprocess communication

execution flow

process blocked

Event diagram for a protocol

request 1

response 1

response2

request 2

time

Page 27: Interprocess Communications - UVa

Distributed Computing, M. L. Liu27

Event Diagram for a HTTP session

web server web browser

request

response

request is a message in 3 parts: - <command> <document adddress> <HTTP version> - an optional header - optional data for CGI data using post method

response is a message consisting of 3 parts: - a status line of the format <protocol><status code><description> - header information, which may span several lines; - the document itself.

Page 28: Interprocess Communications - UVa

Distributed Computing, M. L. Liu28

Sequence Diagram

Process A Process B

interprocess communication

request 1

response 1

request 2

response 2

Page 29: Interprocess Communications - UVa

Distributed Computing, M. L. Liu29

sequence diagram for a HTTP session

Process A Process B

interprocess communication

request 1

response 1

request 2

response 2

Page 30: Interprocess Communications - UVa

Distributed Computing, M. L. Liu30

Protocol

In a distributed application, two processes perform interprocess communication in a mutually agreed upon protocol.The specification of a protocol should include (i) the sequence of data exchange, which can be described using a time event diagram.(ii) the specification of the format of the data exchanged at each step.

Page 31: Interprocess Communications - UVa

Distributed Computing, M. L. Liu31

HTTP: A sample protocol

The Hypertext Transfer Protocol is a protocol for a process (the browser) to obtain a document from a web server process.It is a request/response protocol: a browser sends a request to a web server process, which replies with a response.

Page 32: Interprocess Communications - UVa

Distributed Computing, M. L. Liu32

The Basic HTTP protocol

web server web browser

request

response

request is a message in 3 parts: - <command> <document adddress> <HTTP version> - an optional header - optional data for CGI data using post method

response is a message consisting of 3 parts: - a status line of the format <protocol><status code><description> - header information, which may span several lines; - the document itself.

We will explore HTTP in details later this quarter.

Page 33: Interprocess Communications - UVa

Distributed Computing, M. L. Liu33

A sample HTTP sessionScript started on Tue Oct 10 21:49:28 20009:49pm telnet www.csc.calpoly.edu 80 Trying 129.65.241.20... Connected to tiedye2-srv.csc.calpoly.edu. Escape character is '^]'. GET /~mliu/ HTTP/1.0 HTTP Request HTTP/1.1 200 OK HTTP response status line Date: Wed, 11 Oct 2000 04:51:18 GMT HTTP response header Server: Apache/1.3.9 (Unix) ApacheJServ/1.0 Last-Modified: Tue, 10 Oct 2000 16:51:54 GMT ETag: "1dd1e-e27-39e3492a" Accept-Ranges: bytes Content-Length: 3623 Connection: close Content-Type: text/html <HTML> document content <HEAD> <TITLE> Mei-Ling L. Liu's Home Page </TITLE> </HEAD> <BODY bgcolor=#ffffff> …

Page 34: Interprocess Communications - UVa

Distributed Computing, M. L. Liu34

IPC paradigms and implementations

Paradigms of IPC of different levels of abstraction have evolved, with corresponding implementations.

remote procedure/method

socket API

data transmission serial/parallel communication

Unix socket API, Winsock

Remote Procedure Call (RPC), Java RMI

level ofabstraction IPC paradigms Example IPC Implementations

Page 35: Interprocess Communications - UVa

Distributed Computing, M. L. Liu35

Summary

Interprocess communications (IPC) is the backbone of distributed computing. In this chapter we have looked at the principles of IPC, including the followings:• What is interprocess communication? Unicast?

Multicast? • What is an IPC application programming interface

(API) and what primitive operations does such an interface provide?

• Event synchronization: How do processes engaged in IPC synchronize or coordinate the send and receive operations? What role do blocking operations play in this regard?

Page 36: Interprocess Communications - UVa

Distributed Computing, M. L. Liu36

Summary - 2

• Data representation or encoding schemes: Why is data marshalling necessary? What are the two components involved in data marshalling? What are the different levels of abstraction in data encoding? What is meant by object serialization?

• What is the difference between connection-oriented and connectionless interprocesscommunications? Compare and contrast the two.

Page 37: Interprocess Communications - UVa

Distributed Computing, M. L. Liu37

Summary - 3

• What is an event diagram? How can it be used to describe the sequence of events and their synchronization in a protocol such as the HTTP?

• What is a sequence diagram? How can it be used to describe the sequence of events in a protocol such as the HTTP?

• What are the different levels of abstraction in IPC paradigms?