Download Week3_4_2009

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Two Approaches
Communication-Oriented Design
Begin with the communication protocol. Design a message
format and syntax. Design the client and server
components by specifying how each reacts to incoming
message and how each generates outgoing messages.
Application-Oriented Design
Begin with the application. Design a conventional
application program to solve the problem. Build and test a
working version of the conventional program that operates
on a single machine. Divide the program into two or more
pieces, and add communication protocols that allow each
piece to execute on a separate computer.
Communication in Distributed System


Interprocess communication is at the heart of all
distributed systems. It makes no sense to study
distributed systems without carefully examining
the ways that processes on different machines
can exchange information.
To understand the communication in the
distributed system, two main topics should be
discussed:


Protocols governing the rules that communicating processes must
adhere to.
Models for communication: Remote Procedure Call (RPC), Remote
Method Invocation (RMI), Message-Oriented Middleware (MOM), and
streams.
Middleware layers
Applications
RMI, RPC and events
Request reply protocol
External data representation (XDR)
Operating System
Middleware
layers
Outcomes: RPC
What is RPC?
The difference between conventional procedure call
and RPC?
Understand the function of client and server stubs
How many steps could happen for a RPC?
How RPC deals with the parameter passing?
How to write a client and server using DCE RPC?
Outcomes: Remote Object Invocation
What is so called distributed objects?
How to bind a client to an object?
Implementation of object references
Static vs dynamic remote method
invocations
RPC - Conventional Procedure Call
a)
b)
Parameter passing in a local procedure call: the stack before the call to read
(fd, buf, nbytes)
The stack while the called procedure is active
Definition of Remote Procedure Call
 Principle of RPC between a client and server program.
 When a process on machine A calls a procedure on machine B, the calling
process on A is suspended, and execution of the called procedure takes place
on B. Information can be transported from the caller to the callee in the
parameters and can come back in the procedure result. No message passing
at all is visible to the programmer. This method is known as Remote
Procedure Call.
Client and Server Stubs
2-8
 Steps involved in doing remote computation through RPC
 The function of stub is that, instead of asking operating to give it data, it packs
the parameters into message and requests the message to be sent to the
server. After client stub calls send, it calls receive, block itself until the reply
comes back.
Figure 5.7
Role of client and server stub procedures in RPC
client process
server process
Request
client stub
procedure
client
program
Communication
module
Reply
server stub
procedure
Communication
dispatcher
module
service
procedure
Steps of a Remote Procedure Call
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Client procedure calls client stub in normal way
Client stub builds message, calls local OS
Client's OS sends message to remote OS
Remote OS gives message to server stub
Server stub unpacks parameters, calls server
Server does work, returns result to the stub
Server stub packs it in message, calls local OS
Server's OS sends message to client's OS
Client's OS gives message to client stub
Stub unpacks result, returns to client
Passing Value Parameters
a)
b)
c)
Original message on the Pentium
The message after receipt on the SPARC
The message after being inverted. The little numbers in boxes indicate
the address of each byte
Files interface in Sun XDR
const MAX = 1000;
typedef int FileIdentifier;
typedef int FilePointer;
typedef int Length;
struct Data {
int length;
char buffer[MAX];
};
struct writeargs {
FileIdentifier f;
FilePointer position;
Data data;
};
struct readargs {
FileIdentifier f;
FilePointer position;
Length length;
};
program FILEREADWRITE {
version VERSION {
void WRITE(writeargs)=1;
Data READ(readargs)=2;
}=2;
} = 9999;
1
2
Passing Reference Parameters
 Passing the reference parameter is very difficult:
read(fd, buf, nbytes) example
 One solution is to forbid pointers and reference parameters in
general.
 Strategy : In read example, the client stub knows the buf points
to an array and the array length.
Client stub copies the array into message and send it to the server
Server stub call the server with a pointer to this array
When server (procedure) finishes, the original message can be sent back
to the client stub
Client stub copies buf back to the client (procedure).
 Example ONC RPC call functions:
callrpc(host, prog, progver, procnum, inproc, in, outproc, out);
handle = clan_create (host, prog, vers, proto);
Example: DCE RPC
Services DCE RPC has:
The distributed file service is a world wide file system that
provides a transparent way of accessing any file in the
system in the same way
The directory service is used to keep track of the location
of all resources in the system
The security service allows resources of all kinds to be
protected
The distributed time service is a service that attempts to
keep clocks on the different machines globally
synchronized
Writing a Client and a Server
2-14
 The steps in writing a client and a server in DCE RPC.
Binding a Client to a Server
2-15
 Client-to-server binding in DCE.
 To allow a client to call a server, the server must be registered first
 The steps to locate the server and bind to it:
 Locate the server’s machine
 Locate the server (i.e. the correct process) on that machine
Remote Object Invocation
What is so called distributed objects?
How to bind a client to an object?
Implementation of object references
Static vs dynamic remote method
invocations
Remote and local method invocations
local
remote
invocation
A
B
C
local E
invocation
invocation
local
invocation
D
remote
invocation
F
Distributed Objects
2-16
 Common organization of a remote object with client-side proxy.
1.
2.
Proxy is analogous to a client stub in RPC system. Its work is to marshal method invocation into messages or unmarshl reply messages to return result to client.
Skeleton is analogous to server stub. It works the similar way as proxy.
Binding a Client to an Object
Distr_object* obj_ref;
obj_ref = …;
obj_ref-> do_something();
//Declare a systemwide object reference
// Initialize the reference to a distributed object
// Implicitly bind and invoke a method
(a)
Distr_object objPref;
Local_object* obj_ptr;
obj_ref = …;
obj_ptr = bind(obj_ref);
obj_ptr -> do_something();
//Declare a systemwide object reference
//Declare a pointer to local objects
//Initialize the reference to a distributed object
//Explicitly bind and obtain a pointer to the local proxy
//Invoke a method on the local proxy
(b)
a)
b)
An example with implicit binding using only global references
An example with explicit binding using global and local references
Implementation of Object References
 Object reference must contain enough information to allow a
client to bind to an object. It would include the network address
of the machine where the actual object resides, along with an
endpoint identifying the server that manages the object, plus an
indication of which object.
 To avoid the reassignment of the object reference, for example
the endpoint for the recovery of server from crash, each
machine should have a local daemon to listen to a well-known
endpoint and keep track of the server-to-endpoint assignments
in an endpoint table.
 Using the location server to keep track of the machine where
an object’s server is currently running.
Static versus Dynamic Remote Method Invocations
 Difference between RPC and RMI:
RPC only have general-purpose client-side and server side stubs available.
RMI generally support system wide object references.
 Static Invocation: using predefined interface definitions. It requires
that the interfaces of an object are known when the client
application is being developed. If interfaces change, application
must recompile.
 Dynamic invocation: able to compose a method invocation at
runtime. It takes the form such as:
Invoke(object, method, input_parameters, output_parameters);
 Example: Appending an integer int to a file object fobject:
Static invocation: fobject.append(int)
Dynamic invocation: invoke(fobject, id(append), int)
Figure 5.5
Invocation semantics
Fault tolerance measures
Retransmit request
message
Duplicate
filtering
Invocation
semantics
Re-execute procedure
or retransmit reply
No
Not applicable
Not applicable
Maybe
Yes
No
Re-execute procedure
At-least-once
Yes
Yes
Retransmit reply
At-most-once
Figure 5.11
Java Remote interfaces Shape and ShapeList
import java.rmi.*;
import java.util.Vector;
public interface Shape extends Remote {
int getVersion() throws RemoteException;
GraphicalObject getAllState() throws RemoteException;
1
}
public interface ShapeList extends Remote {
Shape newShape(GraphicalObject g) throws RemoteException; 2
Vector allShapes() throws RemoteException;
int getVersion() throws RemoteException;
}
Figure 5.12
The Naming class of Java RMIregistry
void rebind (String name, Remote obj)
This method is used by a server to register the identifier of a remote object by
name, as shown in next slide, line 3.
void bind (String name, Remote obj)
This method can alternatively be used by a server to register a remote object
by name, but if the name is already bound to a remote object reference an
exception is thrown.
void unbind (String name, Remote obj)
This method removes a binding.
Remote lookup(String name)
This method is used by clients to look up a remote object by name, as shown
in Figure 15.15 line 1. A remote object reference is returned.
String [] list()
This method returns an array of Strings containing the names bound in the
registry.
Figure 5.13
Java class ShapeListServer with main method
import java.rmi.*;
public class ShapeListServer{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try{
ShapeList aShapeList = new ShapeListServant();
Naming.rebind("Shape List", aShapeList );
System.out.println("ShapeList server ready");
}catch(Exception e) {
System.out.println("ShapeList server main " + e.getMessage());}
}
}
1
2
Figure 5.14
Java class ShapeListServant implements interface ShapeList
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
public class ShapeListServant extends UnicastRemoteObject implements ShapeList {
private Vector theList;
// contains the list of Shapes
1
private int version;
public ShapeListServant()throws RemoteException{...}
public Shape newShape(GraphicalObject g) throws RemoteException {
2
version++;
Shape s = new ShapeServant( g, version);
3
theList.addElement(s);
return s;
}
public Vector allShapes()throws RemoteException{...}
public int getVersion() throws RemoteException { ... }
}
Figure 5.15
Java client of ShapeList
import java.rmi.*;
import java.rmi.server.*;
import java.util.Vector;
public class ShapeListClient{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
ShapeList aShapeList = null;
try{
aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList") ;
Vector sList = aShapeList.allShapes();
} catch(RemoteException e) {System.out.println(e.getMessage());
}catch(Exception e) {System.out.println("Client: " + e.getMessage());}
}
}
1
2
Figure 5.16
Classes supporting Java RMI
RemoteObject
RemoteServer
Activatable
UnicastRemoteObject
<servant class>
Message Oriented Communication
Persistence and Synchronicity in Communication (1)
 General organization of a communication system in which hosts are
connected through a network
2-20
Persistence and Synchronicity in Communication (3)
a)
b)
Persistent asynchronous communication
Persistent synchronous communication
2-22.1
Persistence and Synchronicity in Communication (4)
2-22.2
c)
d)
Transient asynchronous communication
Receipt-based transient synchronous communication
Persistence and Synchronicity in Communication (5)
e)
f)
Delivery-based transient synchronous communication at message delivery
Response-based transient synchronous communication
Berkeley Sockets (1)
 Socket primitives for TCP/IP.
Primitive
Meaning
Socket
Create a new communication endpoint
Bind
Attach a local address to a socket
Listen
Announce willingness to accept connections
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
Berkeley Sockets (2)
 Connection-oriented communication pattern using sockets.
The Message-Passing Interface (MPI)
 Some of the most intuitive message-passing primitives of MPI.
Primitive
Meaning
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 receipt 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 are none
MPI_irecv
Check if there is an incoming message, but do not block
Message-Queuing Model (1)
 Four combinations for loosely-coupled communications using queues.
2-26
Message-Queuing Model (2)
 Basic interface to a queue in a message-queuing system.
Primitive
Meaning
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.
General Architecture of a Message-Queuing System (1)
 The relationship between queue-level addressing and network-level
addressing.
General Architecture of a Message-Queuing System (2)
 The general organization of a message-queuing system with routers.
2-29
Message Brokers
 The general organization of a message broker in a message-queuing
system.
2-30
Example: IBM MQSeries
 General organization of IBM's MQSeries message-queuing system.
2-31
Channels
 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
Message Transfer (1)
 The general organization of an MQSeries queuing network
using routing tables and aliases.
Message Transfer (2)
Primitive
Description
MQopen
Open a (possibly remote) queue
MQclose
Close a queue
MQput
Put a message into an opened queue
MQget
Get a message from a (local) queue
 Primitives available in an IBM MQSeries MQI