Communications

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Communications

Distributed Systems
FACULTY OF INFORMATION TECHNOLOGY 1
Communication: Foundations Layered Protocols

Middleware layer

Observation
Middleware is invented to provide common services and protocols that can be
used by many different applications
A rich set of communication protocols
(Un)marshaling of data, necessary for integrated systems
Naming protocols, to allow easy sharing of resources
Security protocols for secure communication
Scaling mechanisms, such as for replication and caching

Note
What remains are truly application-specific protocols... such as?
2
Communication: Foundations Layered Protocols

An adapted layering scheme

Application protocol
Application

Middleware protocol
Middleware

Operating Host-to-host protocol


system

Physical/Link-level protocol
Hardware

Network
3
Communication: Foundations Types of Communication

Types of communication

Distinguish...
Synchronize at Synchronize at Synchronize after
request submission request delivery processing by server
Client

Request

Transmission
interrupt
Storage
facility

Reply

Server Time

Transient versus persistent communication


Asynchronous versus synchronous communication
4
Communication: Foundations Types of Communication

Types of communication
Transient versus persistent
Synchronize at Synchronize at Synchronize after
request submission request delivery processing by server
Client

Request

Transmission
interrupt
Storage
facility

Reply

Server Time

Transient communication: Comm. server discards message when it


cannot be delivered at the next server, or at the receiver.
Persistent communication: A message is stored at a communication
server as long as it takes to deliver it. 5

8 / 49
Communication: Foundations Types of Communication

Types of communication

Places for synchronization


Synchronize at Synchronize at Synchronize after
request submission request delivery processing by server
Client

Request

Transmission
interrupt
Storage
facility

Reply

Server Time

At request submission
At request delivery
After request processing 6
Communication: Foundations Types of Communication

Client/Server

Some observations
Client/Server computing is generally based on a model of transient
synchronous communication:
Client and server have to be active at time of communication
Client issues request and blocks until it receives reply
Server essentially waits only for incoming requests, and subsequently
processes them

Drawbacks synchronous communication


Client cannot do any other work while waiting for reply
Failures have to be handled immediately: the client is waiting
The model may simply not be appropriate (mail, news) 7
Communication: Foundations Types of Communication

Messaging

Message-oriented middleware
Aims at high-level persistent asynchronous communication:
Processes send each other messages, which are queued
Sender need not wait for immediate reply, but can do other things
Middleware often ensures fault tolerance

8
Communication: Remote procedure call Basic RPC operation

Basic RPC operation

Observations
Application developers are familiar with simple procedure model
Well-engineered procedures operate in isolation (black box)
There is no fundamental reason not to execute procedures on separate
machine
Wait for result
Client

Conclusion Call remote Return


procedure from call
Communication between caller & callee
can be hidden by using procedure-call Request Reply
mechanism. Server
Call local procedure Time
and return results

9
Communication: Remote procedure call Basic RPC operation

Basic RPC operation


Client machine Server machine

Client process Server process


1. Client call to
procedure Implementation 6. Stub makes
of doit local call to “doit”
Server stub
r = doit(a,b) r = doit(a,b)
Client stub
proc: “doit” proc: “doit”
type1: val(a) type1: val(a) 5. Stub unpacks
2. Stub builds message
type2: val(b) message type2: val(b)

proc: “doit” 4. Server OS


Client OS type1: val(a) Server OS hands message
type2: val(b) to server stub

3. Message is sent
across the network

1 Client procedure calls client stub. 6 Server does local call; returns result to stub.
2 Stub builds message; calls local OS. 7 Stub builds message; calls OS.
3 OS sends message to remote OS. 8 OS sends message to client’s OS.
4 Remote OS gives message to stub. 9 Client’s OS gives message to stub.
5 Stub unpacks parameters; calls 10 Client stub unpacks result; returns to client.
server.
10
13 / 49
Communication: Remote procedure call Parameter passing

RPC: Parameter passing

There’s more than just wrapping parameters into a message


Client and server machines may have different data representations (think
of byte ordering)
Wrapping a parameter means transforming a value into a sequence of
bytes
Client and server have to agree on the same encoding:

How are basic data values represented (integers, floats, characters)


How are complex data values represented (arrays, unions)

Conclusion
Client and server need to properly interpret messages, transforming them into
machine-dependent representations.
11
Communication: Remote procedure call Parameter passing

RPC: Parameter passing

Some assumptions
Copy in/copy out semantics: while procedure is executed, nothing can be
assumed about parameter values.
All data that is to be operated on is passed by parameters. Excludes
passing references to (global) data.

Conclusion
Full access transparency cannot be realized.

A remote reference mechanism enhances access transparency


Remote reference offers unified access to remote data
Remote references can be passed as parameter in RPCs
Note: stubs can sometimes be used as such references
12
Communication: Remote procedure call Variations on RPC

Asynchronous RPCs

Essence
Try to get rid of the strict request-reply behavior, but let the client continue
without waiting for an answer from the server.

Wait for Callback to client


Client acceptance

Call remote Return


procedure from call Return
results
Accept
Request request

Server Call local procedure Time


13
Communication: Remote procedure call Variations on RPC

Sending out multiple RPCs

Essence
Sending an RPC request to a group of servers.

Server Call local procedure

Callbacks to client
Client

Call remote
procedures

Server Call local procedure Time


14
Communication: Remote procedure call Example: DCE RPC

RPC in practice

Uuidgen

Interface
definition file

IDL compiler

Client code Client stub Header Server stub Server code

#include #include

C compiler C compiler C compiler C compiler

Client Client stub Server stub Server


object file object file object file object file

Runtime Runtime
Linker Linker
library library

Client Server
binary binary 15
Communication: Remote procedure call Example: DCE RPC

Client-to-server binding (DCE)

Issues
(1) Client must locate server machine, and (2) locate the server.

Directory machine

Directory
server
2. Register service
3. Look up server
Server machine
Client machine

5. Do RPC 1. Register port


Server
Client

4. Ask for port DCE


daemon Port
table

16

Binding a client to a server 19 / 49


Communication: Message-oriented communication Simple transient messaging with sockets

Transient messaging: sockets


Berkeley socket interface
Operation Description
socket Create a new communication end point
bind Attach a local address to a socket
listen Tell operating system what the maximum number of pending
connection requests should be
accept Block caller until a connection request arrives
connect Actively attempt to establish a connection
send Send some data over the connection
receive Receive some data over the connection
close Release the connection

Server
socket bind listen accept receive send close

Synchronization point Communication

socket connect send receive close


17
Client
Communication: Message-oriented communication Simple transient messaging with sockets

Sockets: Python code


Server
1 from socket import *
2 s = socket(AF_INET, SOCK_STREAM)
3 s.bind((HOST, PORT))
4 s.listen(1)
5 (conn, addr) = s.accept() # returns new socket and addr. client
6 while True: # forever
7 data = conn.recv(1024) # receive data from client
8 if not data: break # stop if client stopped
9 conn.send(str(data)+"*") # return sent data plus an "*"
10 conn.close() # close the connection

Client
1 from socket import *
2 s = socket(AF_INET, SOCK_STREAM)
3 s.connect((HOST, PORT)) # connect to server (block until accepted)
4 s.send(’Hello, world’) # send same data
5 data = s.recv(1024) # receive the response
6 print data # print the result
7 s.close() # close the connection
18

21 / 49
Communication: Message-oriented communication Advanced transient messaging

Making sockets easier to work with

Observation
Sockets are rather low level and programming mistakes are easily made.
However, the way that they are used is often the same (such as in a
client-server setting).

Alternative: ZeroMQ
Provides a higher level of expression by pairing sockets: one for sending
messages at process P and a corresponding one at process Q for receiving
messages. All communication is asynchronous.

Three patterns
Request-reply
Publish-subscribe
Pipeline
19
Communication: Message-oriented communication Advanced transient messaging

Request-reply

Server
1 import zmq
2 context = zmq.Context()
3
4 p1 = "tcp://"+ HOST +":"+ PORT1 # how and where to connect
5 p2 = "tcp://"+ HOST +":"+ PORT2 # how and where to connect
6 s = context.socket(zmq.REP) # create reply socket
7
8 s.bind(p1) # bind socket to address
9 s.bind(p2) # bind socket to address
10 while True:
11 message = s.recv() # wait for incoming message
12 if not "STOP" in message: # if not to stop...
13 s.send(message + "*") # append "*" to message
14 else: # else...
15 break # break out of loop and end
20
Communication: Message-oriented communication Advanced transient messaging

Request-reply

Client
1 import zmq
2 context = zmq.Context()
3
4 php = "tcp://"+ HOST +":"+ PORT # how and where to connect
5 s = context.socket(zmq.REQ) # create socket
6
7 s.connect(php) # block until connected
8 s.send("Hello World") # send message
9 message = s.recv() # block until response
10 s.send("STOP") # tell server to stop
11 print message # print result
21
Communication: Message-oriented communication Advanced transient messaging

Publish-subscribe
Server
1 import zmq, time
2
3 context = zmq.Context()
4 s = context.socket(zmq.PUB) # create a publisher socket
5 p = "tcp://"+ HOST +":"+ PORT # how and where to communicate
6 s.bind(p) # bind socket to the address
7 while True:
8 time.sleep(5) # wait every 5 seconds
9 s.send("TIME " + time.asctime()) # publish the current time

Client
1 import zmq
2
3 context = zmq.Context()
4 s = context.socket(zmq.SUB) # create a subscriber socket
5 p = "tcp://"+ HOST +":"+ PORT # how and where to communicate
6 s.connect(p) # connect to the server
7 s.setsockopt(zmq.SUBSCRIBE, "TIME") # subscribe to TIME messages
8
9 for i in range(5): # Five iterations
10 time = s.recv() # receive a message
11 print time
Using messaging patterns: ZeroMQ 25 / 49
22
Communication: Message-oriented communication Advanced transient messaging

Pipeline

Source
1 import zmq, time, pickle, sys, random
2
3 context = zmq.Context()
4 me = str(sys.argv[1])
5 s = context.socket(zmq.PUSH) # create a push socket
6 src = SRC1 if me == ’1’ else SRC2 # check task source host
7 prt = PORT1 if me == ’1’ else PORT2 # check task source port
8 p = "tcp://"+ src +":"+ prt # how and where to connect
9 s.bind(p) # bind socket to address
10
11 for i in range(100): # generate 100 workloads
12 workload = random.randint(1, 100) # compute workload
13 s.send(pickle.dumps((me,workload))) # send workload to worker

23
Communication: Message-oriented communication Advanced transient messaging

Pipeline

Worker
1 import zmq, time, pickle, sys
2
3 context = zmq.Context()
4 me = str(sys.argv[1])
5 r = context.socket(zmq.PULL) # create a pull socket
6 p1 = "tcp://"+ SRC1 +":"+ PORT1 # address first task source
7 p2 = "tcp://"+ SRC2 +":"+ PORT2 # address second task source
8 r.connect(p1) # connect to task source 1
9 r.connect(p2) # connect to task source 2
10
11 while True:
12 work = pickle.loads(r.recv()) # receive work from a source
13 time.sleep(work[1]*0.01) # pretend to work

24
Communication: Message-oriented communication Advanced transient messaging

MPI: When lots of flexibility is needed

Representative operations
Operation Description
MPI bsend Append outgoing message to a local send buffer
MPI send Send a message and wait until copied to local or
remote buffer
MPI ssend Send a message and wait until transmission starts
MPI sendrecv Send a message and wait for reply
MPI isend Pass reference to outgoing message, and continue
MPI issend Pass reference to outgoing message, and wait until
receipt starts
MPI recv Receive a message; block if there is none
MPI irecv Check if there is an incoming message, but do not
block
25
Communication: Message-oriented communication Message-oriented persistent communication

Message-oriented middleware

Essence
Asynchronous persistent communication through support of middleware-level
queues. Queues correspond to buffers at communication servers.

Operations
Operation Description
put Append a message to a specified queue
get Block until the specified queue is nonempty, and
remove the first message
poll Check a specified queue for messages, and remove
the first. Never block
notify Install a handler to be called when a message is put
into the specified queue 26
Communication: Message-oriented communication Message-oriented persistent communication

General model

Queue managers
Queues are managed by queue managers. An application can put messages
only into a local queue. Getting a message is possible by extracting it from a
local queue only ) queue managers need to route messages.

Routing
Look up
Source queue contact address Destination queue
manager of destination manager
queue manager
Logical
queue-level
address (name)

Local OS Address lookup


Local OS
database

Contact
Network address 27
Communication: Message-oriented communication Message-oriented persistent communication

Message broker

Observation
Message queuing systems assume a common messaging protocol: all
applications agree on message format (i.e., structure and data representation)

Broker handles application heterogeneity in an MQ system


Transforms incoming messages to target format
Very often acts as an application gateway
May provide subject-based routing capabilities (i.e., publish-subscribe
capabilities)
28
Communication: Message-oriented communication Message-oriented persistent communication

Message broker: general architecture

Source Message broker Destination

Application Application

Broker plugins Rules

Interface Interface
Queuing
layer
Local OS Local OS Local OS

29
Communication: Message-oriented communication Example: IBM’s WebSphere message-queuing system

IBM’s WebSphere MQ
Basic concepts
Application-specific messages are put into, and removed from queues
Queues reside under the regime of a queue manager
Processes can put messages only in local queues, or through an RPC
mechanism

Message transfer
Messages are transferred between queues
Message transfer between queues at different processes, requires a
channel
At each end point of channel is a message channel agent
Message channel agents are responsible for:
Setting up channels using lower-level network communication
facilities (e.g., TCP/IP)
(Un)wrapping messages from/in transport-level packets
Sending/receiving packets 30

Overview 33 / 49
Communication: Message-oriented communication Example: IBM’s WebSphere message-queuing system

IBM’s WebSphere MQ
Schematic overview
Client's receive
Sending client Routing table Send queue queue Receiving client

Queue Queue
manager manager

MQ Interface MQ Interface

Server MCA MCA Server


Stub MCA MCA Stub
stub stub

Enterprise network Local network


RPC Message passing To other remote
(synchronous) (asynchronous) queue managers

Channels are inherently unidirectional


Automatically start MCAs when messages arrive
Any network of queue managers can be created
Routes are set up manually (system administration)
31
Overview 34 / 49
Communication: Message-oriented communication Example: IBM’s WebSphere message-queuing system

Message channel agents

Some attributes associated with message channel agents


Attribute Description
Transport type Determines the transport protocol to be used
FIFO delivery Indicates that messages are to be delivered in the
order they are sent
Message length Maximum length of a single message
Setup retry count Specifies maximum number of retries to start up the
remote MCA
Delivery retries Maximum times MCA will try to put received message
into queue
32
Communication: Message-oriented communication Example: IBM’s WebSphere message-queuing system

IBM’s WebSphere MQ
Routing
By using logical names, in combination with name resolution to local queues, it
is possible to put a message in a remote queue

Alias table Routing table


LA1 QMC QMB SQ1 Routing table
Alias table
LA2 QMD QMC SQ1
LA1 QMA QMA SQ1
QMD SQ2
LA2 QMD QMC SQ1
QMD SQ1
SQ2 SQ1
SQ1
QMA
QMB

Routing table Routing table


SQ1 QMB
QMA SQ1 QMA SQ1
QMC SQ2 QMC SQ1
QMB SQ1 SQ2 QMD SQ1

Alias table
LA1 QMA
SQ1
LA2 QMC
QMD

Message transfer 36 / 49
33

You might also like