Middleware – RPC ,
RMI
By
Prajakta Rane (M.E. EXTC)
Sindhudurg Shikshan Prasarak Mandal’s College of
Engineering, Kankvali,
Sindhdurg
Layered Protocols
OSI LAYER functions
Remote Procedure Call (RPC)
 Remote Procedure Call (RPC) is a powerful
technique for constructing distributed, client-
server based applications.
 It is based on extending the conventional local
procedure calling so that the called procedure
need not exist in the same address space as
the calling procedure.
 The two processes may be on the same system,
or they may be on different systems with a
network connecting them.
Syn & Asyn RPC
 Syn RPC Asyn RPC
1. The calling environment is suspended, procedure parameters
are transferred across the network to the environment where the
procedure is to execute, and the procedure is executed there.
2. When the procedure finishes and produces its results, its results
are transferred back to the calling environment, where execution
resumes as if returning from a regular procedure call.
Client and Server Stub
 In RPC, the calling process at the client side packs
parameters and data into a message called client
stub. This Message transforms digital data into wire
format. The packing of data is also called the
marshaling process.
 The RPC transport sends client stub across the
network to the server side. The server stub is
generated at server side which unpacks client stub
and passes parameters to the called procedure that
generates the result.
 The server stub is also responsible for packing the
result into the message and sending across the
network to the client, where the client stub unpacks it
and sends the result back to the client’s process. The
unpacking of the data is also called the
unmarshaling process.
Working of RPC
1. A client invokes a client stub procedure,
passing parameters in the usual way. The client
stub resides within the client’s own address space.
2. The client stub marshalls(pack) the parameters
into a message. Marshalling includes converting
the representation of the parameters into a
standard format, and copying each parameter into
the message.
3. The client stub passes the message to the
transport layer, which sends it to the remote server
machine.
4. On the server, the transport layer passes the
message to a server stub, which
demarshalls(unpack) the parameters and calls the
desired server routine using the regular procedure
5. When the server procedure completes, it returns
to the server stub (e.g., via a normal procedure
call return), which marshalls the return values into
a message. The server stub then hands the
message to the transport layer.
6. The transport layer sends the result message
back to the client transport layer, which hands the
message back to the client stub.
7. The client stub demarshalls the return
parameters and execution returns to the caller.
Parameter passing in RPC
 Functions in an application that runs in a single process may collaborate
via parameters and/or global variables
 Functions in an application that runs in multiple processes on the same
host may collaborate via message passing and/or nondistributed shared
memory
 However, passing parameters is typically the only way that RPC-based
clients and servers share information. Parameters that are passed by
value are fairly simple to handle
 The client stub copies the value from the client and packages into a
network message
 Consider a remote procedure, sum(i, j), which takes two integer
parameters and returns their arithmetic sum. The client stub takes its
two parameters and puts them in a message and also puts the name or
number of the procedure to be called in the message. When the
message arrives at the server, the stub examines the message to see
which procedure is needed, and then makes the appropriate call.
 When the server has finished execution, it takes the result provided by
the server and packs it into a message. This message is sent back to
the client stub, which unpacks it and returns the value to the client
procedure
 Parameters passed by reference are much harder:
For example distributed systems with distributed
shared-memory mechanisms can allow passing of
parameters by reference.
 A pointer is meaningful only within the address
space of the process in which it is being used.
Suppose there are two parameters to be passed, if
the second parameter is the address of the buffer
which is 1000 on the client, one cannot just pass the
number 1000 to the server and expect it to work.
Address 1000 on the server might be in the middle of
the program text.
 Parameter passed by reference is very difficult to
implement as the server needs to keep the track of
the pointer to the data at the client’s address space.
Extended RPC Models
 Two Models : doors and asynchronous RPC
 Doors –
 Allow server processes to create the door and
client processes to call doors.
 Uses IPC to call a subroutine or a procedure on
the remote host
 Doors are created by the server using
door_create() method , while the client invokes
different procedures on the server using
door_call() method.
 Server process calls door_return() method to
return the result back to called process.
RPC ISSUES
 Issues that must be addressed:
 1. RPC Runtime: RPC run-time system is a library of routines and a set of services
that handle the network communications that underlie the RPC mechanism. In the
course of an RPC call, client-side and server-side run-time systems’ code handle
binding, establish communications over an appropriate protocol, pass call data
between the client and server, and handle communications errors.
 2. Stub: The function of the stub is to provide transparency to the programmer-
written application code.
 On the client side, the stub handles the interface between the client’s local procedure
call and the run-time system, marshaling and unmarshaling data, invoking the RPC
run-time protocol, and if requested, carrying out some of the binding steps.
 On the server side, the stub provides a similar interface between the run-time system
and the local manager procedures that are executed by the server.
 3. Binding: How does the client know who to call, and where the service
resides?
 The most flexible solution is to use dynamic binding and find the server at run time
when the RPC is first made. The first time the client stub is invoked, it contacts a
name server to determine the transport address at which the server resides.
Binding consists of two parts:
 Naming: Remote procedures are named through
interfaces. An interface uniquely identifies a
particular service, describing the types and
numbers of its arguments. It is similar in purpose to
a type definition in programming languauges.
 Locating: Finding the transport address at which the
server actually resides. Once we have the transport
address of the service, we can send messages
directly to the server.
 A Server having a service to offer exports an
interface for it. Exporting an interface registers it with
the system so that clients can use it.
 A Client must import an (exported) interface before
communication can begin.
Advantages
 1. RPC provides ABSTRACTION i.e message-
passing nature of network communication is
hidden from the user.
 2. RPC often omits many of the protocol layers to
improve performance. Even a small performance
improvement is important because a program
may invoke RPCs often.
 3. RPC enables the usage of the applications in
the distributed environment, not only in the local
environment.
 4. With RPC code re-writing / re-developing effort
is minimized.
 5. Process-oriented and thread oriented models
supported by RPC.
Remote Method Invocation
 Used to locate and fetch the objects at remote
side using object reference
 Client machine is always invoker of methods
which initiates the remote method call by using
the local process
RMI Architecture
 Application layer is responsible for running the
client and server applications. When client
invokes a method ,the req is passed to the
proxy layer.
 The proxy layer is responsible for creating
client stub at client side by packing the
request msg sent by client process ans
creating skeleton by packing the response
message sent by server. They are passed to
remote reference layer.
 RRL transmits message and data to RMI
transport layer which responsible for
establishing and maintaining a stream
RMI Process
Difference between RMI and
RPC
RPC RMI
Supports Procedural programming Object oriented
programming
Parameters Ordinary data structures are
passed to remote procedures
Objects are passed to
remote methods
Efficiency Lower than RMI More and supported by
modern programming
approach i.e. object
oriented paradigm
Overheads More Less
In-out
parameters are
mandatory
Yes Not necessary
Provision of
ease of
programming
High Low
Types of Communication
 Persistent and transient communication- In persistent ,
messages sent by the sender are stored by server on the
secondary storage as long as it delivers to receivers
machine.
 Intransient , messages exist till the server and client
processes are in execution an later on are discarded
automatically.
 Synchronous and asynchronous communication – In
synchronous , the sender sends the request to receiver
and waits till it gets a reply from the receiver. So the
sender is blocked for an indefinite time until it gets
response from the receiver. It is the strongest type of
communication where the client and server both need to
be alive for communication.
 In asynchronous , sender sends request to the receiver
and continues further work. It doesn’t wait for a reply from
the receiver.
 Persistent Syn and Persistent Asyn
communication-In persistent syn communication,
sender is blocked till messages are stored on the
server. In asyn communication , messages are stored
on local buffer or server by sender parallel to
transmission without blocking.
 Transient syn and asyn communication- In syn
communication, sender is blocked until messages are
stored on the temp buffer . In asyn communication
sender temporarily stores messages and continues
the transmission.
Message Oriented Transient
Communication
 Message oriented transient communication generally
happens in sockets and message passing interfaces.
 Message passing through sockets:
 Sockets – 1. are communication end points used to
send and receive data over network.
2. using socket processes at client can
speak with processes at server.
3. Server and client interact with each
other using specific port no and IP address.
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
Message Passing Interface(MPI)
 Message-passing interface (MPI)
–Hardware independent
–Designed for parallel applications (uses
transient communication)
 Key idea: communication between groups of
processes
–Each endpoint is a (groupID, processID)
pair
MPI Primitives
 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 oriented Persistent
Communication
 Message queuing systems or Message-Oriented Middleware (MOM)
–Support asynchronous persistent communication
–Intermediate storage for message while sender/receiver are inactive
–Example application: email
Communicate by inserting messages in queues
 Sender is only guaranteed that message will be eventually inserted in
recipient’s queue
 MOM is also called message queuing system. Each machine has queue
attached to it. Any machine who want to send will simply pit the message in
out put queue that transmit the message to the input queue of receiver.
 In MOM, message broker is important component that lies between sender
and receiver. It is responsible for delivering messages from sender to
receiver.
 The put and get primitive are used by message queuing model to send and
receive message.
 Message broker does Message translation, message transformation,
message delivery and message routing. Also forwards message
Message queuing model /General
architecture of MOM
Characteristics of MOM
 Queuing models stops the message from getting lost due
to sender sending faster than receiver receiving or if the
sender is not available.
 It allows the sender to send or broadcast message to
group of recipients.
 It allows message transfer using synchronous or
asynchronous technique.
 It has the support of heterogeneous platforms using
diverse hardware, diverse software and diverse protocols
 Help in storing messages persistently on secondary
storage
 Queues used are scalable with respect to application
 Provides fault tolerance in case of failure occurs
Message queuing System
Stream Oriented Communication
 Message-oriented communication: request-
response
 –When communication occurs and speed do not
affect correctness
 Timing is crucial in certain forms of
communication
–Examples: audio and video (“continuous
media”)
–30 frames/s video => receive and display a
frame every 33ms
 Stream oriented communication is required!
Data Stream
 A data stream is a sequence of data units
 Discrete or continuous:
–Discrete stream
–Continuous stream
 For continuous stream, three transmission modes:
–Asynchronous transmission mode
No timing requirements
–Synchronous transmission mode
Maximum end-to-end delay
–Isochronous transmission mode
Both minimum and maximum end-
to-end delay

Middleware in Distributed System-RPC,RMI

  • 1.
    Middleware – RPC, RMI By Prajakta Rane (M.E. EXTC) Sindhudurg Shikshan Prasarak Mandal’s College of Engineering, Kankvali, Sindhdurg
  • 2.
  • 5.
  • 6.
    Remote Procedure Call(RPC)  Remote Procedure Call (RPC) is a powerful technique for constructing distributed, client- server based applications.  It is based on extending the conventional local procedure calling so that the called procedure need not exist in the same address space as the calling procedure.  The two processes may be on the same system, or they may be on different systems with a network connecting them.
  • 7.
    Syn & AsynRPC  Syn RPC Asyn RPC
  • 8.
    1. The callingenvironment is suspended, procedure parameters are transferred across the network to the environment where the procedure is to execute, and the procedure is executed there. 2. When the procedure finishes and produces its results, its results are transferred back to the calling environment, where execution resumes as if returning from a regular procedure call.
  • 9.
    Client and ServerStub  In RPC, the calling process at the client side packs parameters and data into a message called client stub. This Message transforms digital data into wire format. The packing of data is also called the marshaling process.  The RPC transport sends client stub across the network to the server side. The server stub is generated at server side which unpacks client stub and passes parameters to the called procedure that generates the result.  The server stub is also responsible for packing the result into the message and sending across the network to the client, where the client stub unpacks it and sends the result back to the client’s process. The unpacking of the data is also called the unmarshaling process.
  • 10.
  • 11.
    1. A clientinvokes a client stub procedure, passing parameters in the usual way. The client stub resides within the client’s own address space. 2. The client stub marshalls(pack) the parameters into a message. Marshalling includes converting the representation of the parameters into a standard format, and copying each parameter into the message. 3. The client stub passes the message to the transport layer, which sends it to the remote server machine. 4. On the server, the transport layer passes the message to a server stub, which demarshalls(unpack) the parameters and calls the desired server routine using the regular procedure
  • 12.
    5. When theserver procedure completes, it returns to the server stub (e.g., via a normal procedure call return), which marshalls the return values into a message. The server stub then hands the message to the transport layer. 6. The transport layer sends the result message back to the client transport layer, which hands the message back to the client stub. 7. The client stub demarshalls the return parameters and execution returns to the caller.
  • 13.
    Parameter passing inRPC  Functions in an application that runs in a single process may collaborate via parameters and/or global variables  Functions in an application that runs in multiple processes on the same host may collaborate via message passing and/or nondistributed shared memory  However, passing parameters is typically the only way that RPC-based clients and servers share information. Parameters that are passed by value are fairly simple to handle  The client stub copies the value from the client and packages into a network message  Consider a remote procedure, sum(i, j), which takes two integer parameters and returns their arithmetic sum. The client stub takes its two parameters and puts them in a message and also puts the name or number of the procedure to be called in the message. When the message arrives at the server, the stub examines the message to see which procedure is needed, and then makes the appropriate call.  When the server has finished execution, it takes the result provided by the server and packs it into a message. This message is sent back to the client stub, which unpacks it and returns the value to the client procedure
  • 14.
     Parameters passedby reference are much harder: For example distributed systems with distributed shared-memory mechanisms can allow passing of parameters by reference.  A pointer is meaningful only within the address space of the process in which it is being used. Suppose there are two parameters to be passed, if the second parameter is the address of the buffer which is 1000 on the client, one cannot just pass the number 1000 to the server and expect it to work. Address 1000 on the server might be in the middle of the program text.  Parameter passed by reference is very difficult to implement as the server needs to keep the track of the pointer to the data at the client’s address space.
  • 15.
    Extended RPC Models Two Models : doors and asynchronous RPC  Doors –  Allow server processes to create the door and client processes to call doors.  Uses IPC to call a subroutine or a procedure on the remote host  Doors are created by the server using door_create() method , while the client invokes different procedures on the server using door_call() method.  Server process calls door_return() method to return the result back to called process.
  • 17.
    RPC ISSUES  Issuesthat must be addressed:  1. RPC Runtime: RPC run-time system is a library of routines and a set of services that handle the network communications that underlie the RPC mechanism. In the course of an RPC call, client-side and server-side run-time systems’ code handle binding, establish communications over an appropriate protocol, pass call data between the client and server, and handle communications errors.  2. Stub: The function of the stub is to provide transparency to the programmer- written application code.  On the client side, the stub handles the interface between the client’s local procedure call and the run-time system, marshaling and unmarshaling data, invoking the RPC run-time protocol, and if requested, carrying out some of the binding steps.  On the server side, the stub provides a similar interface between the run-time system and the local manager procedures that are executed by the server.  3. Binding: How does the client know who to call, and where the service resides?  The most flexible solution is to use dynamic binding and find the server at run time when the RPC is first made. The first time the client stub is invoked, it contacts a name server to determine the transport address at which the server resides.
  • 18.
    Binding consists oftwo parts:  Naming: Remote procedures are named through interfaces. An interface uniquely identifies a particular service, describing the types and numbers of its arguments. It is similar in purpose to a type definition in programming languauges.  Locating: Finding the transport address at which the server actually resides. Once we have the transport address of the service, we can send messages directly to the server.  A Server having a service to offer exports an interface for it. Exporting an interface registers it with the system so that clients can use it.  A Client must import an (exported) interface before communication can begin.
  • 19.
    Advantages  1. RPCprovides ABSTRACTION i.e message- passing nature of network communication is hidden from the user.  2. RPC often omits many of the protocol layers to improve performance. Even a small performance improvement is important because a program may invoke RPCs often.  3. RPC enables the usage of the applications in the distributed environment, not only in the local environment.  4. With RPC code re-writing / re-developing effort is minimized.  5. Process-oriented and thread oriented models supported by RPC.
  • 20.
    Remote Method Invocation Used to locate and fetch the objects at remote side using object reference  Client machine is always invoker of methods which initiates the remote method call by using the local process
  • 21.
  • 22.
     Application layeris responsible for running the client and server applications. When client invokes a method ,the req is passed to the proxy layer.  The proxy layer is responsible for creating client stub at client side by packing the request msg sent by client process ans creating skeleton by packing the response message sent by server. They are passed to remote reference layer.  RRL transmits message and data to RMI transport layer which responsible for establishing and maintaining a stream
  • 23.
  • 24.
    Difference between RMIand RPC RPC RMI Supports Procedural programming Object oriented programming Parameters Ordinary data structures are passed to remote procedures Objects are passed to remote methods Efficiency Lower than RMI More and supported by modern programming approach i.e. object oriented paradigm Overheads More Less In-out parameters are mandatory Yes Not necessary Provision of ease of programming High Low
  • 25.
    Types of Communication Persistent and transient communication- In persistent , messages sent by the sender are stored by server on the secondary storage as long as it delivers to receivers machine.  Intransient , messages exist till the server and client processes are in execution an later on are discarded automatically.  Synchronous and asynchronous communication – In synchronous , the sender sends the request to receiver and waits till it gets a reply from the receiver. So the sender is blocked for an indefinite time until it gets response from the receiver. It is the strongest type of communication where the client and server both need to be alive for communication.  In asynchronous , sender sends request to the receiver and continues further work. It doesn’t wait for a reply from the receiver.
  • 26.
     Persistent Synand Persistent Asyn communication-In persistent syn communication, sender is blocked till messages are stored on the server. In asyn communication , messages are stored on local buffer or server by sender parallel to transmission without blocking.  Transient syn and asyn communication- In syn communication, sender is blocked until messages are stored on the temp buffer . In asyn communication sender temporarily stores messages and continues the transmission.
  • 28.
    Message Oriented Transient Communication Message oriented transient communication generally happens in sockets and message passing interfaces.  Message passing through sockets:  Sockets – 1. are communication end points used to send and receive data over network. 2. using socket processes at client can speak with processes at server. 3. Server and client interact with each other using specific port no and IP address.
  • 30.
    Primitive Meaning  SocketCreate 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
  • 31.
    Message Passing Interface(MPI) Message-passing interface (MPI) –Hardware independent –Designed for parallel applications (uses transient communication)  Key idea: communication between groups of processes –Each endpoint is a (groupID, processID) pair
  • 32.
    MPI Primitives  PrimitiveMeaning  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
  • 33.
    Message oriented Persistent Communication Message queuing systems or Message-Oriented Middleware (MOM) –Support asynchronous persistent communication –Intermediate storage for message while sender/receiver are inactive –Example application: email Communicate by inserting messages in queues  Sender is only guaranteed that message will be eventually inserted in recipient’s queue  MOM is also called message queuing system. Each machine has queue attached to it. Any machine who want to send will simply pit the message in out put queue that transmit the message to the input queue of receiver.  In MOM, message broker is important component that lies between sender and receiver. It is responsible for delivering messages from sender to receiver.  The put and get primitive are used by message queuing model to send and receive message.  Message broker does Message translation, message transformation, message delivery and message routing. Also forwards message
  • 34.
    Message queuing model/General architecture of MOM
  • 35.
    Characteristics of MOM Queuing models stops the message from getting lost due to sender sending faster than receiver receiving or if the sender is not available.  It allows the sender to send or broadcast message to group of recipients.  It allows message transfer using synchronous or asynchronous technique.  It has the support of heterogeneous platforms using diverse hardware, diverse software and diverse protocols  Help in storing messages persistently on secondary storage  Queues used are scalable with respect to application  Provides fault tolerance in case of failure occurs
  • 36.
  • 37.
    Stream Oriented Communication Message-oriented communication: request- response  –When communication occurs and speed do not affect correctness  Timing is crucial in certain forms of communication –Examples: audio and video (“continuous media”) –30 frames/s video => receive and display a frame every 33ms  Stream oriented communication is required!
  • 38.
    Data Stream  Adata stream is a sequence of data units  Discrete or continuous: –Discrete stream –Continuous stream  For continuous stream, three transmission modes: –Asynchronous transmission mode No timing requirements –Synchronous transmission mode Maximum end-to-end delay –Isochronous transmission mode Both minimum and maximum end- to-end delay