Distributed Web Systems

currygeckoΛογισμικό & κατασκευή λογ/κού

2 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

90 εμφανίσεις

Distributed Web Systems
Interprocess Communications
Lecturer
Department
University
Outline

Interprocess communications

Marshalling

Group communications
Interprocess
communication

Message exchange, two primitive operations:

send

receive
Applications, services
Middleware
layers
request-reply protocol
marshalling and external data representation
UDP and TCP
This
lecture
RMI and RPC
Types of communication

Synchronous

the sender is blocked on the “send” until the receiver
performs “receive”

sending and receiving processes synchronise at every
message

Asynchronous


send” is non-blocking (message is copied into a local
buffer and transmitted in parallel with the sending
process)


receive” can be blocking or non-blocking

Multi-threading can remove disadvantages of the
blocking operations
Message destinations

In the Internet context:

internet address
– identifies a particular
computer on the network

fixed address or…

symbolic host name – resolved using name services (more
on this later)

local port number
– identifies a particular
process running on that machine
API for Internet protocols

Sockets

a programming abstraction

an endpoint for communication between processes

associated with

a
protocol

(
UDP
,
TCP
)

an
internet address
of the host

a local
port number
message
agreed port
any port
socket
socket
Internet address = 138.37.88.249
Internet address = 138.37.94.248
other ports
client
server
© Pearson Education 2005
Communication over UDP

Message size is usually restricted (networking
settings)

Non-blocking “send” and blocking “receive”

but
“receive”
can use
timeouts


receive” returns the Internet address and port of the
sender

Possible failures
:

messages can be lost

messages can be corrupted

messages can be delivered out of order
Advantages?
UDP in Java

Socket:

DatagramSocket
class

send
and
receive
methods

new DatagramSocket (portNum)
– create socket bound
to a specific port (server)

new DatagramSocket ()
– the port for the socket is
chosen by the operating system (client)

Data:

DatagramPacket class

Stores message data and addressing information

new DatagramPacket (data, length, address, port)

getData
,
getLength
,
getAddress
,
getPort
methods
UDP example
DatagramSocket aSocket = null;

try {
aSocket = new DatagramSocket();

InetAddress aHost = InetAddress.
getByName
(
hostName
);
int serverPort = 6789;

DatagramPacket request = new DatagramPacket(m
sg
,

msgLen
, aHost, serverPort);
aSocket.send(request);

byte[] buffer = new byte[1000];
DatagramPacket reply = new DatagramPacket(buffer,

buffer.length);
aSocket.receive(reply);
System.out.println("Reply: " +

new String(reply.getData()));

}catch (SocketException e)

{System.out.println("Socket: " + e.getMessage());}

finally {if(aSocket != null) aSocket.close();}
Communication over TCP

Provides
abstraction of a stream
to which data
can be written to and read from
in arbitrary chunks

Behind the scenes:

message partitioning, retransmission of lost packets, flow
control, packets ordering
, connection (no need for
destination in each send)

Data are queued on both ends

Blocking:


send” does not block when there is space in the send
queue


receive” does not block when there is data to read in the
receive queue
Communication over TCP
send queue
receive queue
network
sending
process
receiving
process
send()
receive()
Disad
vantages?
Advantage – makes
application development
easier:
no need to worry
about many communication
related problems
Communications over TCP

Possible communication failures
:

D
oes not guarantee the delivery
of data in the
send queue
(congested network, high packet
loss, etc)

Other problems:

when connection is broken, cannot distinguish
between network and
the receiving
process
failure
TCP in Java

Sockets:

Socket
class – client

creation of the object tries to establish a connection to server

ServerSocket
class – server

to accept a connection from a client, call the
accept
method.
Returns a
Socket
object for this connection

Data:

transmitted through streams

DataInputStream
class – receive

DataOutputStream
class – send

similar to file operations

to obtain – call
getInputStream
or
getOutputStream
on
the Socket object
Marshalling

Within processes, information is stored in data
structures – on the network messages consist
a

sequence of bytes

Data Marshalling:

Taking collection of data items and assembling them into
a form suitable for network transmission (unmarshallling
= the reverse process)

Example
s
:

Java object serialization
(binary)

XML (textual)
Marshalling (contd.)

Design considerations:

Human readability

Textual versus binary

Compactness, flexibility

Fixed message sizes versus variable message sizes

Ease of programming marshalling/unmarshalling
functions

Simple rigid formats versus complex flexible ones
Marshalling (examples)

Transmitting an array of bytes:

byte [] data = {10, 20, 30, 40, 50}

Binary, fixed length:

Binary, variable length:

5 10 20 30 40 50
length
10 20 30 40 50
Marshalling (examples
contd.)

Transmitting an array of bytes:

byte [] data = {10, 20, 30, 40, 50}

XML:
<array>

<element>10</element>

<element>20</element>

<element>30</element>

<element>40</element>

<element>50</element>
</array>
Marshalling (contd.)

Other design considerations:

Platform dependency

Big versus little-endian

architectures

Character encodings

(ASCII, Unicode, etc)

Inclusion of the type information

Data only (e.g. CORBA)

Data and types (e.g. Java serialization)
C
lient-server
communication: request-
reply

doOperation:

marshalling -> send -> receive -> unmarshalling
Request
Server
Client
doOperation
(wait)
(continuation)
Reply
message
getRequest
execute
method
message
select object
sendReply
© Pearson Education 2005
request-reply analysis

Implemented over UDP:

Need to deal with lost requests and replies

Special measures required to transfer large data
structures (due to limited packet size)

Implemented over TCP:

TCP takes care of
lost messages

and
partitioning of large data chunks

Lost
messages
can still occur (recall the server
cannot distinguish between network and client
failures!)
Disadvan
tage
s?
Group communications

Multicast messaging

scenarios:

Client talking to replicated server (fault tolerance)

Discovering servers in spontaneous networking

Delivering data updates to data storage replicas

Propagating event notification to distributed processes

IP multicast:

built on top of UDP

same failure
problems

Java API

MulticastSocket

class
Summary

Interprocess communication is done via
message
exchange

Sockets
– a standard API for Internet protocols
(UDP, TCP)

Marshalling
is about assembling application data
into a form suitable for transmission of a network

Questions