0% found this document useful (0 votes)
34 views

Chapter 2

The document discusses interprocess communications (IPC) in distributed computing systems. It describes different types of IPC including unicast and multicast. It also explains synchronous and asynchronous communication and the operations typically provided by IPC APIs.

Uploaded by

Marina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Chapter 2

The document discusses interprocess communications (IPC) in distributed computing systems. It describes different types of IPC including unicast and multicast. It also explains synchronous and asynchronous communication and the operations typically provided by IPC APIs.

Uploaded by

Marina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Interprocess Communications

Mei-Ling L. Liu

1 Distributed Computing, M. L. Liu


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.
Distributed Computing, M. L. Liu
2
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.

Distributed Computing, M. L. Liu


3
Unicast vs. Multicast

P2 P2 P3 ... P4

m
m m m

P1 P1

uni c as t m ul ti c as t
Distributed Computing, M. L. Liu
4
Interprocess Communications in
Distributed Computing

P ro c es s 1 P roc es s 2

data

s en der rec eiver

Distributed Computing, M. L. Liu


5
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.

Distributed Computing, M. L. Liu


6
Interprocess Communication in basic HTTP

W e b s e rv e r

S1 S2 S3 S4
o p e r a ti o n s :
H TTP S 1 : a cce pt co n n e cti o n
a pro ce s s S 2 : r e c e i ve (r e q u e s t )
re qu e s t
S 3 : s e n d (r e s p o n s e )
a n o p e ra t i o n S 3 : d i s co n n e c t
H TTP
C 1 : m a k e co n n e ct i o n
re s p o n s e
C 2 : s e n d (r e q u e s t )
da ta fl o w C 3 : r e c e i ve (r e s p o n s e )
C1 C2 C3 C4
C 4 : d i s co n n e ct

W e b bro ws e r

Distributed Computing, M. L. Liu


7
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.

Distributed Computing, M. L. Liu


8
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.

Distributed Computing, M. L. Liu


9
Synchronous send and receive

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

b lo c k in g r ec eiv e s tar ts

b lo c k in g s en d s tarts an o p eratio n

ex ec u tio n flo w
ac k n o w led g em en t o f d ata rec eiv ed s u s p en d ed p er io d
b lo c k in g s en d r etu r n s p ro v id ed b y th e I P C f ac ility b lo c k in g r ec eiv e en d s

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

Distributed Computing, M. L. Liu


10
Asynchronous send and synchronous
receive
P rocess 2
P r o c e ss 1

b lo c k in g r ec eiv e s tar ts

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

o p er atio n
ex ec u tio n f lo w
s u s p en d ed p erio d
b lo c k in g r ec eiv e r etu r n s

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

Distributed Computing, M. L. Liu


11
Synchronous send and Async. Receive - 1

P rocess 2
P rocess 1

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

n o n b lo c k in g r ec eiv e is s u ed
tr an s p aren t ac k n o w led g em en t
p r o v id ed b y th e IP C fac ility ex ec u tio n flo w
s u s p en d ed p erio d

Sync hr o no us Se nd and
As ync hr o no us R e c e i ve
S ce n a rio A

Distributed Computing, M. L. Liu


12
Synchronous send and Async. Receive - 2

P rocess 2
P rocess 1

n o n b lo c k in g r ec eiv e is s u ed
an d r etu r n ed im m ed iately
b lo c k in g s en d is s u ed

in d efin ite
b lo c k in g ex ec u tio n flo w
s u s p en d ed p er io d

P rocess 2
P rocess 1 Sync hr o no us Se nd and
As ync hr o no us R e c e i ve
S ce n a rio B

Distributed Computing, M. L. Liu


13
Synchronous send and Async. Receive - 3

P rocess 2
P rocess 1

n o n b lo c k in g rec eiv e is s u ed
an d retu r n ed im m ed iately
b lo c k in g s en d is s u ed
p ro c es s is n o tif ied
tr an s p aren t ac k n o w led g em en t o f th e ar riv al o f
p r o v id ed b y th e IP C fac ility d ata
ex ec u tio n flo w
s u s p en d ed p erio d

Sync hr o no us Se nd and
As ync hr o no us R e c e i ve
S ce n a rio C

Distributed Computing, M. L. Liu


14
Asynchronous send and Asynchronous
receive

P rocess 2
P rocess 1

n o n b lo c k in g rec eiv e is s u ed
an d retu r n ed im m ed iately
b lo c k in g s en d is s u ed
p ro c es s is n o tif ied
o f th e ar riv al o f
d ata
ex ec u tio n flo w
s u s p en d ed p erio d

As ync hr o no us Se nd and
As ync hr o no us R e c e i ve
S ce n a rio C

Distributed Computing, M. L. Liu


15
Event diagram
P ro ce s s B
P ro ce s s A

t im e
r eq u es t 1

r es p o n s e 1

r eq u es t 2
in ter p r o c es s c o m m u n ic atio n
ex ec u tio n f lo w
r es p o n s e2
p r o c es s b lo c k ed

E ve n t d i ag r am fo r a pr o to c o l
Distributed Computing, M. L. Liu
16
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. P ro c es s 1 P ro c es s 2

rec eiv e fro m p ro c es s 2 is s u ed


p ro c es s 1 b lo c k ed p en d in g d ata
fro m p ro c es s 2 .
rec eiv ed fro m p ro c es s 1 is s u ed
p ro c es s 2 b lo c k ed p en d in g d ata
fro m p ro c es s 1 .

Distributed Computing, M. L. Liu


17
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 read

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

th r ead is b lo c k ed
m ain th read c o n tin u es w ith
o th er p ro c es s in g
th r ead is u n b lo c k ed af ter th e o p er atio n is f u lf illed

Distributed Computing, M. L. Liu


18
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

Distributed Computing, M. L. Liu


19
Indefinite blocking due to a deadlock

Pro ce s s 1 Pro ce s s 2

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


pro ce s s 1 blo ck e d pe n din g da ta
fro m pro ce s s 2 .
" re ce iv e f ro m pro ce s s 1 " is s u e d;
pro ce s s 2 blo ck e d pe n din g da ta
a n o pe ra ti o n
fro m pro ce s s 1 .
p r o ce s s
e x e cu ti n g
p r o ce s s
b l o ck e d

Distributed Computing, M. L. Liu


20
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)

Distributed Computing, M. L. Liu


21
Data Encoding Protocols

le v e l o f a bs tra ctio n
da t a e n co din g s ch e m e s S a m ple S ta n da rds

ap p lic atio n s p ec if ic d ata en c o d in g lan g u ag e X M L:(E x ten s ib le M ark u p L an g u ag e)

g en er al d ata en c o d in g lan g u ag e
AS N .1 ( Ab s trac t S y n tax N o tatio n )

S u n X D R ( Ex ter n al D ata R ep r es en tatio n )


n etw o r k d ata en c o d in g s tan d ard

Distributed Computing, M. L. Liu


22
Sample XML file
http://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>

Distributed Computing, M. L. Liu


23
Data Marshalling

"T h is is a tes t."


1 .2 7 .3 -1.5
1 . f la tte n in g o f s tr u c tu r ed d ata item s
h ost A m a rsh a llin g
2 . c o n v er tin g d ata to ex te r n al ( n etw o r k )
r ep r e s e n tatio n
1 1 0 0 1 1 . .. 1 0 0 0 0 1 0 0 .. .

1 . c o n v er t d a ta to in ter n a l r ep r e s e n ta tio n
u n m a rsh a llin g
2 . r eb u ild d a ta s tr u c tu r e s .

"T h is is a te s t. "
-1.5 E x ter n al to in te r n a l r ep r e s e n ta tio n an d v ic e v e r s a
is n o t r eq u ir ed
7.3 - if th e tw o s id es a r e o f th e s am e h o s t ty p e ;
1.2 - if th e tw o s id es n eg o tia tes at c o n n ec tio n .

host B

Distributed Computing, M. L. Liu


24
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.

Distributed Computing, M. L. Liu


25
Event diagram for a protocol session
P ro ce s s 2
Pro ce s s 1

t im e
r eq u e s t 1

r es p o n s e 1

r eq u es t 2
in ter p r o c es s c o m m u n ic atio n
ex ec u tio n f lo w
r es p o n s e2
p r o c es s b lo c k ed

E ve nt di ag r am fo r a p r o t o c o l

Distributed Computing, M. L. Liu


26
Event Diagram for a HTTP session

w eb s erver w eb brow s er

request is a m ess age in 3 parts :


request
- < c om m and> < doc um ent adddress > < HT T P version>
- an optional header
- optional data for CG I data using post m ethod

response respons e is a m essage c ons isting of 3 parts:


- a status line of the form at < protoc ol> < s tatus c ode> < desc ription>
- header inform ation, w hic h m ay span several lines;
- the doc um ent itself.

Distributed Computing, M. L. Liu


27
Sequence Diagram
Pro ce s s A Pro ce s s B

req u es t 1

res p o n s e 1

req u es t 2

in ter p r o c es s c o m m u n ic atio n
res p o n s e 2

Distributed Computing, M. L. Liu


28
sequence diagram for a HTTP session
Pro ce s s A Pro ce s s B

req u es t 1

res p o n s e 1

req u es t 2

in ter p r o c es s c o m m u n ic atio n
res p o n s e 2

Distributed Computing, M. L. Liu


29
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.

Distributed Computing, M. L. Liu


30
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.

Distributed Computing, M. L. Liu


31
The Basic HTTP protocol
w eb s erver w eb brow s er

reques t is a m es s age in 3 parts :


reques t
- < c om m and> < doc um ent adddress > < HT T P vers ion>
- an optional header
- optional data for C G I data us ing pos t m ethod

res pons e res pons e is a m es s age c onsis ting of 3 parts :


- a s tatus line of the form at < protoc ol> < s tatus c ode> < des c ription>
- header inform ation, w hic h m ay s pan s everal lines ;
- the doc um ent itself.

W e w ill explore HT T P in details later this quarter.

Distributed Computing, M. L. Liu


32
A sample HTTP session
S cript started on Tue Oct 10 21:49:28 2000
9:49pm telnet www.csc.calpoly.edu 80
Trying 129.65.241.20...
Connected to tiedye2-srv.csc.calpoly.edu.
E scape character is '^]'.
GE T /~mliu/ HTTP/1.0 HT T P R equest

HTTP/1.1 200 OK HT T P response status line


Date: Wed, 11 Oct 2000 04:51:18 GMT HT T P response header
S erver: Apache/1.3.9 (Unix) ApacheJ S erv/1.0
Last-Modified: Tue, 10 Oct 2000 16:51:54 GMT
E Tag: "1dd1e-e27-39e3492a"
Accept-Ranges: bytes
Content-Length: 3623
Connection: close
Content-Type: text/html

<HTML> document content


<HE AD>
<TITLE > Mei-Ling L. Liu's Home Page
</TITLE >
</HE AD>
<BODY bgcolor=#ffffff>

Distributed Computing, M. L. Liu
33
IPC paradigms and implementations
Paradigms of IPC of different levels of abstraction have evolved,
with corresponding implementations.

le ve l o f
I PC pa ra dig m s Ex a m ple I PC I m ple m e n t at io n s
a bs tra ctio n
re m o te p ro ce d u re /m e th o d R em o te P ro c ed u re C all ( R P C ) , J av a R M I
so cke t API Un ix s o c k et AP I , W in s o c k

d a ta tra n smissio n s erial/p arallel c o m m u n ic atio n

Distributed Computing, M. L. Liu


34
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?

Distributed Computing, M. L. Liu


35
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 interprocess
communications? Compare and contrast the two.

Distributed Computing, M. L. Liu


36
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?

Distributed Computing, M. L. Liu


37

You might also like