Distributed Computing 1 Interprocess Communications.

30
Distributed Computing 1 Interprocess Communications

Transcript of Distributed Computing 1 Interprocess Communications.

Page 1: Distributed Computing 1 Interprocess Communications.

Distributed Computing1

Interprocess Communications

Page 2: Distributed Computing 1 Interprocess Communications.

Distributed Computing2

Interprocess Communications

- Operating systems provide facilities for interprocess communications (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: Distributed Computing 1 Interprocess Communications.

Distributed Computing3

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: Distributed Computing 1 Interprocess Communications.

Distributed Computing4

Unicast vs. Multicast

P 2

P 1 P 1

P 2 P 3 P 4...

uni c as t m ul t i c as t

mm m m

Page 5: Distributed Computing 1 Interprocess Communications.

Distributed Computing5

P r o c es s 1 P r o c es s 2

d a ta

s en d er r ec e iv er

Interprocess Communications in Distributed Computing

Page 6: Distributed Computing 1 Interprocess Communications.

Distributed Computing6

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: Distributed Computing 1 Interprocess Communications.

Distributed Computing7

Interprocess Communication in basic HTTP

C 1 C 2

S 3 S 4

C 4

W e b s e rv e r

W e b bro ws e r

a p r o c e s s

a n o p e r a t i o n

d a t a f l o w

o p e r a t i o n s :S 1 : a c c e p t c o n n e c t i o nS 2 : r e c e i ve ( r e q u e s t )S 3 : s e n d ( r e s p o n s e )S 3 : d i s c o n n e c tC 1 : m a k e c o n n e c t i o nC 2 : s e n d ( r e q u e s t )C 3 : r e c e i ve ( r e s p o n s e )C 4 : d i s c o n n e c t

S 2

C 3

S 1

H TTPr e q u e s t

H TTPr e s p o n s e

Page 8: Distributed Computing 1 Interprocess Communications.

Distributed Computing8

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: Distributed Computing 1 Interprocess Communications.

Distributed Computing9

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: Distributed Computing 1 Interprocess Communications.

Distributed Computing10

Synchronous send and receive

pr o c e s s 1r unni ng o n ho s t 1

b lo c k in g s en d s ta r ts

b lo c k in g s en d r e tu r n s

b lo c k in g r ec e iv e s ta r ts

b lo c k in g r ec e iv e en d s

ex ec u tio n f lo w

s u s p en d ed p er io d

Sync hr o no us Se nd and R e c e i ve

an o p er a tio n

ac k n o w led g em en t o f d a ta r ec e iv edp r o v id ed b y th e I P C f ac ility

pr o c e s s 2r unni ng o n ho s t 2

Page 11: Distributed Computing 1 Interprocess Communications.

Distributed Computing11

Asynchronous send and synchronous receive

P r o c e s s 1

P r o c e s s 2

b lo c k in g r ec e iv e s ta r ts

b lo c k in g r ec e iv e r e tu r n s

ex ec u tio n f lo w

s u s p en d ed p er io d

As ync hr o no us Se nd and Sync hr o no us R e c e i ve

n o n b lo c k in g s en d

o p er a tio n

Page 12: Distributed Computing 1 Interprocess Communications.

Distributed Computing12

Synchronous send and Async. Receive - 1

P r o c e s s 1

P r o c e s s 2

n o n b lo c k in g r ec e iv e is s u ed

ex ec u tio n f lo w

s u s p en d ed p er io d

Sync hr o no us Se nd and As ync hr o no us R e c e i ve

b lo c k in g s en d is s u ed

S ce n a rio A

t r an s p ar en t ac k n o w led g em en tp r o v id ed b y th e I P C f ac ility

Page 13: Distributed Computing 1 Interprocess Communications.

Distributed Computing13

Synchronous send and Async. Receive - 2

in d ef in iteb lo c k in g

P r o c e s s 1

P r o c e s s 2

n o n b lo c k in g r ec e iv e is s u edan d r e tu r n ed im m ed ia te ly

ex ec u tio n f lo w

s u s p en d ed p er io d

Sync hr o no us Se nd and As ync hr o no us R e c e i ve

b lo c k in g s en d is s u ed

S ce n a rio B

P r o c e s s 1

P r o c e s s 2

Page 14: Distributed Computing 1 Interprocess Communications.

Distributed Computing14

Synchronous send and Async. Receive - 3

P r o c e s s 1

P r o c e s s 2

n o n b lo c k in g r ec e iv e is s u edan d r e tu r n ed im m ed ia te ly

ex ec u tio n f lo w

s u s p en d ed p er io d

Sync hr o no us Se nd and As ync hr o no us R e c e i ve

b lo c k in g s en d is s u ed

S ce n a rio C

p r o c es s is n o tif iedo f th e a r r iv a l o fd a ta

tr an s p ar en t ac k n o w led g em en tp r o v id ed b y th e I P C f ac ility

Page 15: Distributed Computing 1 Interprocess Communications.

Distributed Computing15

Asynchronous send and Asynchronous receive

P r o c e s s 1

P r o c e s s 2

n o n b lo c k in g r ec e iv e is s u edan d r e tu r n ed im m ed ia te ly

ex ec u tio n f lo w

s u s p en d ed p er io d

As ync hr o no us Se nd and As ync hr o no us R e c e i ve

b lo c k in g s en d is s u ed

S ce n a rio C

p r o c es s is n o tif iedo f th e a r r iv a l o fd a ta

Page 16: Distributed Computing 1 Interprocess Communications.

Distributed Computing16

Event diagram

Pro ce s s APro ce s s B

in te rp r o c es s c o m m u n ic a tio n

ex ec u tio n f lo w

p ro c es s b lo c k ed

E ve nt di ag r am fo r a pr o to c o l

r eq u es t 1

r es p o n s e 1

r es p o n s e2

r eq u es t 2

t im e

Page 17: Distributed Computing 1 Interprocess Communications.

Distributed Computing17

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.

r ec e iv e f r o m p r o c es s 2 is s u ed

r ec e iv ed f r o m p r o c es s 1 is s u ed

p r o c es s 1 b lo c k ed p en d in g d a taf r o m p r o c es s 2 .

p r o c es s 2 b lo c k ed p en d in g d a taf r o m p r o c es s 1 .

P r o c es s 1 P r o c es s 2

Page 18: Distributed Computing 1 Interprocess Communications.

Distributed Computing18

Using threads for asynchronous IPC

When using an IPC programming interface, it is important to note whether 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.

pro ce s s

m ain th r ead

n ew th r ead is s u es a b lo c k in g I P C o p er a tio n

th r ead is b lo c k ed

th r ead is u n b lo c k ed af te r th e o p er a tio n is f u lf illed

m ain th r ead c o n tin u es w itho th er p r o c es s in g

Page 19: Distributed Computing 1 Interprocess Communications.

Distributed Computing19

Deadlocks and Timeouts

Connect and receive operations can result in indefinite blocking

For 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: Distributed Computing 1 Interprocess Communications.

Distributed Computing20

Indefinite blocking due to a deadlock

" re ce iv e f ro m pro ce s s 2 " is s u e d;

" re ce iv e f ro m pro ce s s 1 " is s u e d;

pro ce s s 1 blo ck e d pe n din g da tafro m pro ce s s 2 .

pro ce s s 2 blo ck e d pe n din g da tafro m pro ce s s 1 .

Pro ce s s 1 Pro ce s s 2

p r o c e s se x e c u t i n g

p r o c e s sb l o c k e d

a n o p e r a t i o n

Page 21: Distributed Computing 1 Interprocess Communications.

Distributed Computing21

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 XDR ASN.1 (Abstract Syntax Notation) XML (Extensible Markup Language)

Page 22: Distributed Computing 1 Interprocess Communications.

Distributed Computing22

Data Encoding Protocols

ap p lic a tio n s p ec if ic d a ta en c o d in g lan g u ag e

g en er a l d a ta en c o d in g lan g u ag e

n etw o r k d a ta en c o d in g s tan d ar d

da ta e n co din g s ch e m e s S a m ple S ta n da rdsle v e l o f a bs tra ct io n

X M L :( Ex ten s ib le M ar k u p L an g u ag e)

AS N .1 ( Ab s tr ac t S y n tax N o ta tio n )

S u n X D R ( E x ter n a l D ata R ep r es en ta tio n )

Page 23: Distributed Computing 1 Interprocess Communications.

Distributed Computing23

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 24: Distributed Computing 1 Interprocess Communications.

Distributed Computing24

Event diagram for a protocol session

Pro ce s s 1Pro ce s s 2

in te rp r o c es s c o m m u n ic a tio n

ex ec u tio n f lo w

p ro c es s b lo c k ed

E ve nt di ag r am fo r a pr o to c o l

r eq u es t 1

r es p o n s e 1

r es p o n s e2

r eq u es t 2

t im e

Page 25: Distributed Computing 1 Interprocess Communications.

Distributed Computing25

Event Diagram for a HTTP session

w eb s er v er w eb b r o w s er

r eq u es t

r es p o n s e

r eq u es t is a m es s ag e in 3 p ar ts : - < c o m m an d > < d o c u m en t ad d d r es s > < HT T P v er s io n > - an o p tio n al h ead er - o p tio n a l d a ta f o r C G I d a ta u s in g p o s t m eth o d

r es p o n s e is a m es s ag e c o n s is t in g o f 3 p ar ts : - a s ta tu s lin e o f th e f o r m at < p r o to c o l> < s ta tu s c o d e> < d es c r ip tio n > - h ead er in f o r m atio n , w h ic h m ay s p an s ev er a l lin es ; - th e d o c u m en t its e lf .

Page 26: Distributed Computing 1 Interprocess Communications.

Distributed Computing26

Sequence Diagram

Pro ce s s A Pro ce s s B

in te r p r o c es s c o m m u n ic a tio n

r eq u es t 1

r es p o n s e 1

r eq u es t 2

r es p o n s e 2

Page 27: Distributed Computing 1 Interprocess Communications.

Distributed Computing27

sequence diagram for a HTTP session

Pro ce s s A Pro ce s s B

in te r p r o c es s c o m m u n ic a tio n

r eq u es t 1

r es p o n s e 1

r eq u es t 2

r es p o n s e 2

Page 28: Distributed Computing 1 Interprocess Communications.

Distributed Computing28

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 29: Distributed Computing 1 Interprocess Communications.

Distributed Computing29

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 30: Distributed Computing 1 Interprocess Communications.

Distributed Computing30

The Basic HTTP protocol

w eb s er v er w eb b r o w s er

r eq u es t

r es p o n s e

r eq u es t is a m es s ag e in 3 p ar ts : - < c o m m an d > < d o c u m en t ad d d r es s > < HT T P v er s io n > - an o p tio n a l h ead er - o p tio n a l d a ta f o r C G I d a ta u s in g p o s t m eth o d

r es p o n s e is a m es s ag e c o n s is t in g o f 3 p ar ts : - a s ta tu s lin e o f th e f o r m at < p r o to c o l> < s ta tu s c o d e> < d es c r ip tio n > - h ead er in f o r m atio n , w h ic h m ay s p an s ev er a l lin es ; - th e d o c u m en t its e lf .

W e w ill ex p lo r e HT T P in d e ta ils la te r th is q u ar te r .