Professional Documents
Culture Documents
1
Interprocess Communications
- Exchange of data between two or more separate,
independent processes/threads.
- Operating systems provide facilities/resources for inter-
process communications (IPC), such as message queues,
semaphores, and shared memory.
- Distributed computing systems make use of these
facilities/resources to provide application programming
interface (API) which allows IPC to be programmed at a
higher level of abstraction. (e.g., send and receive)
- Distributed computing requires information to be exchanged
among independent processes.
2
IPC – unicast and multicast
In distributed computing, two or more processes engage in
IPC using 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, e.g., Socket
communication. When communication is from one process
to a group of processes, the IPC is said to be a multicast,
e.g., Publish/Subscribe Message model, a topic that we
will explore in a later chapter.
3
Unicast vs. Multicast
P 2 P 2 P 3 ... P 4
m
m m m
P 1 P 1
4
Interprocess Communications in Distributed
Computing
P ro c ess 1 P ro c ess 2
d a ta
sender r e c e iv e r
5
Operations provided in an archetypal
Interprocess Communications API
6
Interprocess Communication in basic HTTP
W e b server
S1 S2 S3 S4
o p e ra tio n s:
H TTP S 1 : a cce p t co n n e ctio n
a proce ss S 2 : re ce ive (re q u e s t)
re qu e st
S 3 : se n d (re s p o n s e )
a n o p e ra tio n Ss43 : d i s c o n n e c t
H TTP
C 1 : m a k e co n n e ctio n
re spon se
C 2 : se n d (re q u e st)
d a ta flo w C 3 : re ce ive (re sp o n se )
C 1 C 2 C 3 C 4
C 4 : disco n n e ct
W e b brow se r
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.
9
Synchronous send and receive
pro cess 1 process 2
running on host 2
running o n ho st 1
Event Diagram
b lo c k in g r e c e iv e s t a r t s
b lo c k in g s e n d s t a r t s a n o p e r a t io n
e x e c u t io n f lo w
a c k n o w le d g e m e n t o f d a t a r e c e iv e d s u s p e n d e d p e r io d
b lo c k in g s e n d r e t u r n s p r o v id e d b y t h e I P C f a c ilit y b lo c k in g r e c e iv e e n d s
Client Server
Sender Receiver
10
Asynchronous send and synchronous
receive
P ro cess 2
P ro cess 1
Event Diagram
b lo c k in g r e c e iv e s t a r t s
n o n b lo c k in g s e n d
o p e r a t io n
e x e c u t io n f lo w
s u s p e n d e d p e r io d
b lo c k in g r e c e iv e r e t u r n s
Client Server
Sender Receiver
11
Synchronous send and Async. Receive - 1
P rocess 2
P rocess 1
b lo c k in g s e n d is s u e d
n o n b lo c k in g r e c e iv e is s u e d
t r a n s p a r e n t a c k n o w le d g e m e n t
p r o v id e d b y t h e I P C f a c ilit y e x e c u t io n f lo w
s u s p e n d e d p e r io d
n o n b lo c k in g r e c e iv e is s u e d
a n d r e t u r n e d im m e d ia t e ly
b lo c k in g s e n d is s u e d
in d e f in it e
b lo c k in g e x e c u t io n f lo w
s u s p e n d e d p e r io d
P ro cess 2
P rocess 1 Synchronous Send and
A synchro no us R eceive
S c e n a r io B
P rocess 2
P ro cess 1
n o n b lo c k in g r e c e iv e is s u e d
a n d r e t u r n e d im m e d ia t e ly
b lo c k in g s e n d is s u e d
p r o c e s s is n o t if ie d
t r a n s p a r e n t a c k n o w le d g e m e n t o f t h e a r r iv a l o f
p r o v id e d b y t h e I P C f a c ilit y d a ta
e x e c u t io n f lo w
s u s p e n d e d p e r io d
n o n b lo c k in g r e c e iv e is s u e d
a n d r e t u r n e d im m e d ia t e ly
b lo c k in g s e n d is s u e d
p r o c e s s is n o t if ie d
o f t h e a r r iv a l o f
d a ta
e x e c u t io n f lo w
s u s p e n d e d p e r io d
t im e
req u est 1
respo n se 1
req u est 2
in t e r p r o c e s s c o m m u n ic a t io n
e x e c u t io n f lo w
resp o n se2
p r o c e s s b lo c k e d
E v e n t d i a g r a m fo r a p r o t o c o l
r e c e iv e f r o m p r o c e s s 2 is s u e d
p r o c e s s 1 b lo c k e d p e n d in g d a t a
fro m p ro c ess 2 .
r e c e iv e d f r o m p r o c e s s 1 is s u e d
p r o c e s s 2 b lo c k e d p e n d in g d a t a
fro m p ro c ess 1 .
m a in t h r e a d
new t h r e a d is s u e s a b lo c k in g I P C o p e r a t io n
t h r e a d is b lo c k e d
m a in t h r e a d c o n t in u e s w it h
o t h e r p r o c e s s in g
t h r e a d is u n b lo c k e d a f t e r t h e o p e r a t io n is f u lf ille d
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
19
Indefinite blocking due to a deadlock
P roce ss 1 P roce ss 2
" r e c e iv e fr o m p r o c e s s 2 " is s u e d ;
p r o c e s s 1 b lo c k e d p e n d in g d a t a
fro m proce ss 2 .
" r e c e iv e f r o m p r o c e s s 1 " is s u e d ;
p r o c e s s 2 b lo c k e d p e n d in g d a t a
a n o p e ra tio n
fro m pro ce ss 1 .
proce ss
e x e cu tin g
proce ss
blo ck e d
le v e l o f a b s t r a c t io n
d a t a e n c o d in g s c h e m e s S a m p le S t a n d a r d s
a p p lic a tio n s p e c if ic d a ta e n c o d in g la n g u a g e X M L :( E x te n s ib le M a r k u p L a n g u a g e )
g e n e r a l d a ta e n c o d in g la n g u a g e
A S N .1 ( A b s tr a c t S y n ta x N o ta tio n )
S u n X D R ( E x te r n a l D a ta R e p r e s e n ta tio n )
n e tw o r k d a ta e n c o d in g s ta n d a r d
22
Sample XML file
http://java.sun.com/xml/docs/tutorial/overview/1_xml.html#intro
23
Data Marshalling
" T h is i s a t e s t . "
1 .2 7 .3 -1 .5
1 . f la t t e n i n g o f s t r u c t u r e d d a t a i t e m s
host A m a rsh a llin g
2 . c o n v e r t in g d a t a t o e x t e r n a l ( n e t w o r k )
r e p r e s e n t a t io n
1 1 0 0 1 1 ... 1 0 0 0 0 1 0 0 ...
1 . c o n v e r t d a t a t o in t e r n a l r e p r e s e n t a t i o n
u n m a rsh a llin g
2 . r e b u il d d a t a s t r u c t u r e s .
" T h is is a t e s t . "
-1 .5 E x t e r n a l t o in t e r n a l r e p r e s e n t a t io n a n d v ic e v e r s a
is n o t r e q u ir e d
7 .3 - i f t h e t w o s id e s a r e o f t h e s a m e h o s t t y p e ;
1 .2 - i f t h e t w o s id e s n e g o t i a t e s a t c o n n e c t i o n .
24 host B
The OSI (Open System Interconnection ) Seven-
layer network architecture
a p p lic a t io n la y e r a p p lic a t io n la y e r
p r e s e n t a t io n la y e r p r e s e n t a t io n la y e r
s e s s io n la y e r
Message
s e s s io n la y e r
t r a n s p o r t la y e r t r a n s p o r t la y e r
Segment
n e t w o r k la y e r
Datagram n e t w o r k la y e r
p h y s ic a l la y e r 0/1 p h y s ic a l la y e r
25
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.
26
Event diagram
P roce ss 2
P roce ss 1
tim e
req u est 1
resp o n se 1
req u est 2
in t e r p r o c e s s c o m m u n ic a t io n
e x e c u t io n f lo w
resp o n se2
p r o c e s s b lo c k e d
E v e n t d i a g r a m fo r a p r o t o c o l
27
Event Diagram for a HTTP session
w eb serv er w eb b ro w ser
r e q u e s t is a m e s s a g e in 3 p a r t s :
req u est
- < c o m m a n d > < d o c u m e n t a d d d r e s s > < H T T P v e r s io n >
- a n o p t io n a l h e a d e r
- o p t io n a l d a t a f o r C G I d a t a u s in g p o s t m e t h o d
resp o n se r e s p o n s e is a m e s s a g e c o n s is t in g o f 3 p a r t s :
- a s t a t u s lin e o f t h e f o r m a t < p r o t o c o l> < s t a t u s c o d e > < d e s c r ip t io n >
- h e a d e r in f o r m a t io n , w h ic h m a y s p a n s e v e r a l lin e s ;
- t h e d o c u m e n t it s e lf .
28
Sequence Diagram
Process A Process B
req u est 1
resp o n se 1
req u est 2
in t e r p r o c e s s c o m m u n ic a t io n
resp o n se 2
29
Sequence diagram for a HTTP session
Process A Process B
req u est 1
resp o n se 1
req u est 2
in t e r p r o c e s s c o m m u n ic a t io n
resp o n se 2
30
Protocol
31
HTTP: A sample protocol
32
The Basic HTTP protocol
w eb serv er w eb b ro w ser
r e q u e s t is a m e s s a g e in 3 p a r t s :
req u est
- < c o m m a n d > < d o c u m e n t a d d d r e s s > < H T T P v e r s io n >
- a n o p t io n a l h e a d e r
- o p t io n a l d a t a f o r C G I d a t a u s in g p o s t m e t h o d
resp o n se r e s p o n s e is a m e s s a g e c o n s is t in g o f 3 p a r t s :
- a s t a t u s lin e o f t h e f o r m a t < p r o t o c o l> < s t a t u s c o d e > < d e s c r ip t io n >
- h e a d e r in f o r m a t io n , w h ic h m a y s p a n s e v e r a l lin e s ;
- t h e d o c u m e n t it s e lf .
W e w ill e x p lo r e H T T P in d e t a ils la t e r t h is q u a r t e r .
33
A sample HTTP session
Script 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.
Escape character is '^]'.
GET /~mliu/ HTTP/1.0 HTTP Request
34
HTTP Session
Type above commands and hit carriage return twice, you send this
minimal but complete GET request to HTTP server
35
IPC paradigms and implementations
Paradigms of IPC of different levels of abstraction have evolved,
with corresponding implementations.
le v e l o f
I P C p a r a d ig m s E x a m p le I P C I m p le m e n t a tio n s
a b s tr a c tio n
r e m o te p ro c e d u re /m e th o d R e m o t e P r o c e d u r e C a ll ( R P C ) , J a v a R M I
socket API U n ix s o c k e t A P I , W in s o c k
d a t a t r a n s m is s io n s e r ia l/ p a r a lle l c o m m u n ic a t io n