LU2.2-Remote Procedure Calls Updated
LU2.2-Remote Procedure Calls Updated
LU2.2-Remote Procedure Calls Updated
2
Middleware layers
Middleware Layer
• Middleware is:
• an application that lives in the OSI application layer.
• invented to provide common services and protocols that can be used
by many different applications:
• A rich set of communication protocols, but which allow different applications
to communicate
• (Un)marshaling of data, necessary for integrated systems
• Naming protocols, so that different applications can easily share resources
• Security protocols, to allow different applications to communicate in a secure
way
• Scaling mechanisms, such as support for replication and caching
• Examples: Domain name system (DNS), authentication
protocols, distributed locking protocols, remote procedure call
• Note: what remains are truly application-specific protocols
4
Problems with sockets
Sockets interface is
straightforward
• [connect]
• read/write
• [disconnect]
ImpleExample.java
1. public class ImplExample implements Hello {
2. // Implementing the interface method
3. public void printMsg() {
4. System.out.println("This is an example RMI program");
5. }
6. public String getMsg(String a) {
7. return "Server:$ Hello Client " + a;
8. }
9. }
RMI - Server
1. import java.rmi.registry.*;
2. import java.rmi.*;
3. public class HelloServer {
4. public static void main(String args[]) {
5. try {
6. System.setProperty("java.rmi.server.hostname", "192.168.1.1");
7. // Instantiating the implementation class
8. ImplExample obj = new ImplExample();
9. // Binding the remote object (stub) in the registry
10. Naming.rebind("rmi://192.168.1.1:5000/Hello",obj);
11. System.err.println("Server ready");
12. } catch (Exception e) {
13. System.err.println("Server exception: " + e.toString());
14. e.printStackTrace();}
15. }
16.}
RMI - Client
1. import java.rmi.*;
2. public class HelloClient {
3. private HelloClient() {}
4. public static void main(String[] args) {
5. try { // Looking up the registry for the remote object
6. Hello stub = (Hello) Naming.lookup("rmi://192.168.1.1:5000/Hello");
7. // Calling the remote method using the obtained object
8. stub.printMsg();
9. } catch (Exception e) { System.err.println("Client exception: " + e.toString());
e.printStackTrace(); }
10. }
11. }
RPC
1984: Birrell & Nelson
• Mechanism to call procedures on other machines
Create stub functions to make it appear to the user that the call is
local
server stub
client stub
(skeleton)
client server
Stub functions
2. Stub marshals params to net message
server stub
client stub
(skeleton)
client server
Stub functions
3. Network message sent to server
server stub
client stub
(skeleton)
client server
Stub functions
4. Receive message: send to stub
server stub
client stub
(skeleton)
client server
Stub functions
5. Unmarshal parameters, call server func
server stub
client stub
(skeleton)
client server
Stub functions
6. Return from server function
server stub
client stub
(skeleton)
client server
Stub functions
7. Marshal return value and send message
server stub
client stub
(skeleton)
client server
Stub functions
8. Transfer message over network
server stub
client stub
(skeleton)
client server
Stub functions
9. Receive message: direct to stub
server stub
client stub
(skeleton)
client server
Stub functions
10. Unmarshal return, return to client code
server stub
client stub
(skeleton)
client server
RPC: Characteristics
• Called procedure is in another process which may reside
in another machine.
• The processes do not share address space.
• Passing of parameters by reference and passing pointer values
are not allowed.
• Parameters are passed by values.
• Called remote procedure executes within the
environment of the server process.
• The called procedure does not have access to the calling
procedure's (client’s) environment.
27
RPC: Features
• Simple call syntax
• Familiar semantics
• Well defined interface
• Ease of use
• Being able to communicate between processes on the
same machine or different machines
28
RPC: Limitations
• Parameters: passed by values only and pointer values are not
allowed.
• Speed: remote procedure calling (and return) time (i.e.,
overheads) can be significantly (1 - 3 orders of magnitude)
slower than that for local procedure.
• This may affect real-time design and the programmer should be aware
of its impact.
• Failure issues: RPC is more vulnerable to failure (why?).
• The programmers should be aware of the call semantics, i.e., programs
that make use of RPC must have the capability of handling errors that
cannot occur in local procedure calls.
29
RPC: Mechanism
• Marshalling (at sender): the process of taking a collection
of data items and assembling them into a form suitable for
transmission in a message;
• Unmarshalling (at receiver): the process of disassembling
them on arrival to produce an equivalent collection of
data items at the destination.
30
RPC: Mechanism
• How does the client transfer its call request (the procedure
name) and the arguments to the server via network?
• Marshalling and communication with server:
• For each RPC, a (client) stub procedure is generated and attached to
the (client) program.
• Replace the remote procedure call to a (local) call to the stub
procedure.
• The (codes in the) stub procedure marshals (the input) arguments and
places them into a message together with the procedure identifier (of
the remote procedure).
• Use IPC primitive to send the (call request) message to the server and
wait the reply (call return) message.
31
RPC: Mechanism
• How does the server react the request of the client? From
which port? How to select the procedure? How to interpret the
arguments?
• Dispatching, unmarshalling, communication with client:
• A despatcher is provided. It receives the call request message from the
client and uses the procedure identifier in the message to select one of
the server stub procedures and passes on the arguments.
33
RPC: Implementation
• The software that supports RPC has three main tasks:
• Interface processing: integrate the RPC mechanism with client
and server programs in conventional programming languages.
• Communication handling: transmitting and receiving request
and reply messages.
• Binding: locating an appropriate server for a particular service.
34
RPC: Implementation
• Interface Processing: An interface definition may be used as
basis on which to construct the extra software components of
the client and server programs enabling RPC.
• Building the client program: An RPC system provides a means to build
a complete client program by having sub procedure to stand in for
each RPC.
• Building the server program: An RPC system provides a dispatcher and
set of server sub procedures.
• An interface compiler in an RPC system processes interface definitions
to produce components that can be combined with client and server
programs:
• Generating a client stub procedure: The sub procedures will be compiled and
linked with client program.
35
RPC: Implementation
• Generating a server stub procedure, the dispatcher and the server stub
will be compiled and linked with the server program;
• Use the signatures of the procedures in the interface to generate
marshalling and unmarshalling operations in each stub procedure;
• Generating procedure headings for each procedure in the service from
the interface definition;
37
RPC: Implementation
• Binder: a separate service that maintains a table containing
mappings from service names to server ports.
• All other services depend on the binder service.
• Binder interface used by server
• Register (String serviceName, Port serverPort, int version)
• Withdraw (String serviceName, Port serverPort, int version)
• Binder interface used by client
• PortLookUp (String serviceName, int version)
38
Where to bind?
Need to locate host and correct server process
Where to bind? – Solution 1
• Maintain centralized DB that can locate a host that
provides a particular service (Birrell & Nelson’s 1984
proposal)
Where to bind? – Solution 2
• A server on each host maintains a DB of locally provided
services
Security
• messages visible over network
• Authenticate client
• Authenticate server
Interface Definition Language
• A specification language which allow programmer to
specify remote procedure interfaces
(names, parameters, return values)
client stub
server skeleton
server functions
Code you write
Server functions
• Generally need little or no modification
RPC API
What kind of services does an RPC system need?
• Name service operations
• Export/lookup binding information (ports, machines)
• Support dynamic ports
• Binding operations
• Establish client/server communications using appropriate protocol
(establish endpoints)
• Endpoint operations
• Listen for requests, export endpoint to name server
RPC API
What kind of services does an RPC system need?
• Security operations
• Authenticate client/server
• Internationalization operations
• Marshaling/data conversion operations
• Stub memory management
• Dealing with “reference” data, temporary buffers
• Program ID operations
• Allow applications to access IDs of RPC interfaces
Types of Communication (1/3)
• Distinguish:
• Transient versus persistent communication
• Asynchronous versus synchronous communication
51
Types of Communication (2/3)
• Transient (impermanent) communication:
• A message is discarded by a communication server as soon as it
cannot be delivered at the next server, or at the receiver (store and
forward router – drop the message if it cannot deliver the message to
the next or destination host)
• All transport level communication services offer transient
communication.
• Persistent (nonstop / uninterrupted) communication:
• A message is stored at a communication server as long as it takes to
deliver it at the receiver (message that has been submitted for
transmission is stored by communication middleware as long as it takes
to deliver it to the receiver)
• Example: email
52
Types of Communication (3/3)
• Asynchronous communication
• Sender continues immediately after it has submitted its message for
transmission
• E.g. discussion boards (Dialogue that takes place over a period of time),
messaging (One-to-one or one-to-many communications)
• Synchronous communication
• Sender is blocked until its request is known to be accepted
• Places for synchronization:
• At request submission – middleware notifies that it will take over transmission of the
request
• At request delivery to the intended recipient
• After request is fully processing – up the time that the recipient returns a response
• Ex: Audio conferencing and video conferencing.
53
Client / Server communication
• Client/Server communication is generally based on a model of
transient synchronous communication:
• It’s designed to support the roles and message exchanges in typical
client-server interactions.
• Client and server have to be active at the time of communication
• Client issues request and blocks until it receives reply
• Server essentially waits only for incoming requests, and subsequently
processes them
55
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
56
RPC: Design Issues
• Exception handling
• Necessary because of possibility of network and nodes failures;
• RPC uses return value to indicate errors;
• Transparency
• Syntactic → achievable, exactly the same syntax as a local
procedure call;
• Semantic → impossible because of RPC limitation: failure (similar
but not exactly the same);
57
RPC: Design Issues
• Delivery guarantees
• Retry request message: whether to retransmit the request
message until either a reply or the server is assumed to be failed;
• Duplicate filtering: when retransmission are used, whether to filter
out duplicates at the server;
• Retransmission of replies: whether to keep a history of reply
messages to enable lost replies to be retransmitted without re-
executing the server operations.
58
Asynchronous RPCs (1/2)
• Try to get rid of the strict request-reply behavior, but let the
client continue without waiting for an answer from the
server.
61
Transient Messaging: Socket
• Many distributed systems and
application are built on top
of the simple message-
oriented model offered by
the transport layer.
• Example: Consider the
Berkeley socket interface,
which has been adopted by
all UNIX systems, as well as
Windows
Connection-oriented communication pattern
using sockets
Socket Programming
• Refer to eLeap for self-study material on Socket
Programming.
• You are encourage to try, to ensure you understand the
later topics.
Message-Oriented Middleware
• It is an asynchronous persistent communication through support of
middleware-level queues.
• How it works?
• Application communicate by inserting message s in specific queues (Queues
correspond to buffers at communication servers).
• Message are forwarded over a series of communication servers and delivered
to the destination (even if it was down when the message was sent)
• Each application has it own private queue, and can be read only by its
associated application, and possible for multiple applications to share a single
queue.
• Guarantee the message will inserted in the recipient’s queue, but
not when if the message will be read (depends on the recipient’s
behavior)
64
Basic interface to a queue in a message-queuing system
Message Broker
• Message queuing systems assume a common messaging
protocol: all applications agree on message format (i.e.,
structure and data presentation), but with a highly diverse
system it is not a simply task
• Application can provide information on the organization of its
message and semantics of the message
• Message broker: Centralized component that takes care of
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 ⇒ Enterprise
Application Integration
66
The general organization of a message broker in a message-queue
system
67
Multicast Communication
• Why multicast communication?
• Sending data to multiple receivers
• Issue
• Setting up the communication paths for information dissemination
• Involved a huge management effort -> require human intervention
• Today with peer-to-peer technology and notably structured
overlay management, it because easier to set up
communication paths
• Deploy at application layer
• Gossip-based information dissemination
68
Application-Level tree-based multicasting
• Organize nodes of a distributed system into an overlay
network and use that network to disseminate data
• Initiator generates a multicast identifier (mid).
• Lookup succ(mid), the node responsible for mid
• Request is routed to succ(mid), which will become the root.
• If P wants to join, it sends a join request to the root.
• When request arrives at Q:
• Q has not seen a join request before ⇒ it becomes forwarder; P becomes
child of Q. Join request continues to be forwarded.
• Q knows about tree ⇒ P becomes child of Q. No need to forward join
request anymore.
69
Gossip based information Dissemination -
Epidemic Algorithms - Outline
• General background
• Update models
• Removing objects
70
Principles
• Basic idea:
• Update operations are initially performed at one or only a few replicas
• A replica passes its updated state to a limited number of neighbors
• Update propagation is lazy, i.e., not immediate
• Eventually, each update should reach every replica
• Epidemic / Gossiping :
• A replica which has just been updated (i.e., has been contaminated), tells a
number of other replicas about its update (contaminating them as well).
• Infected: holds data that it is willing to spread to other
• Susceptible: A node that has not yet seen this data
• Removed: An updated node that is not willing or able to spread its data
• Goal: to rapidly propagate information among a large collection of nodes
using only local information, no central component to coordinate the
dissemination
71
Anti-Entropy
• Each replica regularly chooses another replica at random,
and exchanges state differences, leading to identical
states at both afterwards
• Approaches to exchanging updates:
• Push: P only sends its updates to Q (Chance of Q to be
susceptible?)
• Pull: P only retrieves updates from Q (Chance of P to be
infected?)
• Push-Pull: P and Q exchange mutual updates (after which they
hold the same information).
72
Deleting Values
• Fundamental problem: We cannot remove an old value from a
server and expect the removal to propagate. Instead, removal will
be undone in due time using epidemic algorithms
• Solution: Removal has to be registered as a special update by
inserting a death certificate
• Next problem: When to remove a death certificate (it is not allowed
to stay for ever):
• Run a global algorithm to detect whether the removal is known everywhere,
and then collect the death certificates (looks like garbage collection)
• Assume death certificates propagate in finite time, and associate a maximum
lifetime for a certificate (can be done at risk of not reaching all servers)
• Note: it is necessary that a removal actually reaches all servers.
73
Unsupervised Lab
• Please refer to eLeap for lab material on RPC
• This is unsupervised lab (you are on your 3rd / 4th year
anyway), please do it on your own time
Thank You
Any Question?
75