RPC new

download RPC new

of 60

Transcript of RPC new

  • 8/2/2019 RPC new

    1/60

    2. Remote ProcedureCall (RPC)

  • 8/2/2019 RPC new

    2/60

    2

    2.1 Introduction

    RPC is a protocol that one program can use to request a

    service from a program located in another comp

    RPC is anIPC technology that allows a program to cause aprocedure to execute in another address space.

    When this mechanism is implemented using object-oriented

    principles, it is called Remote Method Invocation (RMI)

    RPC is a popular way of implementing client-server model ofDistributed Computing

    where, Requesting program is a Client

    Service providing program is a Server

    RPC is used by both, an O.S. & by applications..

    NFS is implemented as a set of RPCs

    DCOM , CORBA, Java RMI are RPCs

  • 8/2/2019 RPC new

    3/60

    3

    RPC is an extension ofprocedure callmechanism

    It enables a call to be made to a procedure thatdoes not reside in the address space of the callingprocedure

    The called procedure (remote) can be on the samecomputer as that of the calling procedure or on adifferent computer

    In this case, as the caller and callee processes have

    different address spaces , there is no shared dataHence, RPC uses message passing scheme for

    communication.

  • 8/2/2019 RPC new

    4/60

    4

    Caller Callee

    (Client) (Server)

    Caller

    Proc blocked

    Proc

    executes

    Resume

    Exec.

  • 8/2/2019 RPC new

    5/60

    5

    Issues in Transparency..

    A transparent RPC mechanism is the one in

    which, local procedure and remote procedure

    are indistinguishable to the user.

    This requires two types of transparencies. Syntactic transparency

    Semantic transparency

  • 8/2/2019 RPC new

    6/60

    6

    2.2 Implementation of RPC To achieve the goal of transparency, implementation of RPC is

    based on concept of STUBs

    Which provide a normal procedure call abstraction by

    concealing from programs the interface to the underlying

    RPC system.

    RPC involves two processes : Client & Server

    Hence to achieve transparency, a separatestub process is

    associated with each of the two processes

    Also, to hide the existence and functional details of the

    underlying network, RPC communication package called

    RPC Runtime is used on both the sides.

  • 8/2/2019 RPC new

    7/60

    7

    Elements involved in implementation of RPC

    Mechanism :

    The Client

    The Client StubRPC Runtime

    The Server Stub

    The Server

  • 8/2/2019 RPC new

    8/60

    8

    Client Server

    Client stub Server stub

    RPC Runtime RPC Runtime

    Return Call

    Unpack Pack

    Receive Send

    Call Return

    Unpack Pack

    Receive Send

  • 8/2/2019 RPC new

    9/60

    9

    Client :

    A user process that initiates a remote procedure call Client Stub :

    Responsible for two jobs :

    On receipt of a request call from client,

    It packs specifications of the target procedure &

    arguments into a message

    Then asks the local RPC Runtime routine to

    send it to the server stub

    On receipt of result of procedure execution,

    it unpacks the result and passes it to the client.

  • 8/2/2019 RPC new

    10/60

    10

    RPC Runtime:

    Responsible for transmission of messages across the

    network between the client and server.

    On Client Machine --

    It receives a call request message from the client stub &

    sends it to the server machine.

    It also receives message containing result of procedure

    execution from server machine & passes it to the client

    stub.

    On Server Machine --

    It receives message containing the result of procedure

    execution from server stub & sends it to the client

    machine.

    It also receives call request message from the client

    machine & passes it to the server stub.

  • 8/2/2019 RPC new

    11/60

    11

    Server Stub :

    Responsible for two jobs :

    On receipt of a request call message from local RPCruntime,

    It unpacks it and makes a normal call to invoke

    appropriate procedure in the server.

    On receipt of result of procedure execution, it packs the result into a message and then asks the local

    RPC Runtime to send it to the client stub.

    Server :

    It executes appropriate procedure & returns result ofprocedure execution to the server stub

  • 8/2/2019 RPC new

    12/60

    12

  • 8/2/2019 RPC new

    13/60

    13

  • 8/2/2019 RPC new

    14/60

    14

  • 8/2/2019 RPC new

    15/60

    15

    2.3 RPC Messages :

    Types of messages involved in implementation of RPC :

    Call Messages: sent by client to server requesting

    execution of a remote procedure

    Reply Messages:sent by server to client for returning result

    of remote procedure execution

  • 8/2/2019 RPC new

    16/60

    16

    1. Call Messages:

    Components of a call message :-

    Identification information of the remote procedure to beexecuted i.e.Remote procedure identifier.

    Thearguments necessary for execution of the procedure

    Additional Fields:- Message identification field : has a sequence no. for

    identifying lost messages and duplicate messages.

    Client identification field : to allow the server toidentify the client.

  • 8/2/2019 RPC new

    17/60

    17

    Message Type field : used to distinguish call message

    from reply message

    0 call message

    1 reply message

    RPCcall message format:

  • 8/2/2019 RPC new

    18/60

    18

    2. Reply Messages:

    When the server of an RPC receives a call message, it could

    be faced with one of the following conditions:

    Call message violates RPC protocol

    Action: Server rejects such a call.

    Server detects by scanning clients id. Finds that it is notauthorized to use the service

    Action: Server returns an unsuccessful reply.

    Remote procedure specified in the remote procedure id.Field of the call message is not available with it

    Action:Server returns an unsuccessful reply.

  • 8/2/2019 RPC new

    19/60

    19

    Incompatible RPC interface being used by the client and

    server.

    Action: Server returns an unsuccessful reply.

    An exception condition (Division by zero) occurs during

    execution of remote procedure

    Action: Server returns an unsuccessful reply.

    The specified procedure is executed successfully

    Action: Successful reply.

  • 8/2/2019 RPC new

    20/60

    20

    Fields in theReply Message :

    Message Identifier Field : same as call message.

    Message Type :Indicates it is a reply message.

    Reply status : 0Successful reply

    1 / non-zero value Unsuccessful reply

    Result : Result of procedure execution.

    Reason : Reason for failure

  • 8/2/2019 RPC new

    21/60

    21

    Asuccessfulreply message:

    An unsuccessfulreply message:

  • 8/2/2019 RPC new

    22/60

    22

    2.4 Marshalling arguments and results:

    Implementation of RPC involves transfer of arguments from the client process to the server process and, Transfer of results from server process to client process.

    These arguments and results are transferred in form of

    message data between two computers.

    In RPC, packing parameters into a message is known as

    marshalling

  • 8/2/2019 RPC new

    23/60

    23

    Steps in Marshalling :

    1. Taking arguments (of client) or result (of server) that

    will form message data to be sent to remote process.

    2.Encoding the message data.

    3.Decoding the message data.

    For successful marshalling, the client & server ,both

    should know the methods used.

  • 8/2/2019 RPC new

    24/60

    24

    Marshalling procedures:

    Provided as a part of RPC software

    Best way

    User-defined methods

  • 8/2/2019 RPC new

    25/60

    25

    2.5 Server Implementation :

    Based on the style of implementation used, servers can beof two types:

    Stateful servers

    Stateless servers

  • 8/2/2019 RPC new

    26/60

    26

    Stateful server:

    A stateful server maintains the clients state

    information from one remote procedure call to thenext.

    i.e. in case of two subsequent calls, some state info.

    related to service performed for the client as a result of

    first service call execution is stored by the server

    process.

    This clients state information is subsequently used at

    the time of execution of second call

  • 8/2/2019 RPC new

    27/60

    27

    Stateless server:

    A stateless serverdoes not maintain any client

    state information.

    Hence, every request from the client MUST beaccompanied with all necessary parameters to

    successfully carry out the desired operation.

    Server doesnt keep track of any informationresulting from previous operation.client has tokeep the track

  • 8/2/2019 RPC new

    28/60

    28

    Advantage of Stateful over stateless server:

    They relieve the clients from keeping track of the

    state information

  • 8/2/2019 RPC new

    29/60

    29

    Advantage of Stateless over stateful:

    They have an advantage in terms of failure.

    E.g. with stateful server, if the server crashes, & thenrestarts, the state information that it was holding may

    be lost and, client process might continue its task

    unaware of the crash, producing unwanted results.

    Hence, the client of a stateful server should bedesigned to detect server crashes , to do necessary error

    handling.

    Whereas, with stateless, a client has to only retry a

    request until the server responds; it does not need toknow that the server has crashed.

    The choice is purely APPLICATION DEPENDENT.

  • 8/2/2019 RPC new

    30/60

    30

    2.6 Client-Server Binding:

    It is necessary for a client to know the location ofa server before a remote procedure call can take

    place between them.

    The process by which a client becomes associated

    with a server so that calls can take place is known

    asBinding

  • 8/2/2019 RPC new

    31/60

    31

    Issues in Client-server binding process:

    How does a client specify a server to which it wants to get

    bound?

    How does the binding process locate the specified server ?

    When is it proper to bind a client to a server?

    Is it possible for a client to change a binding duringexecution ?

    Can a client be simultaneously bound to multiple serversthat provide the same service ?

  • 8/2/2019 RPC new

    32/60

    32

    2.6.1 How does a client specify a server to which it wants to

    get bound?

    Server Naming :

    The specification of a client by a server with which it

    wants to communicates a naming issue.

    Solution.Use of Interface. Two parts of Interface name:

    Type

    Instance.

  • 8/2/2019 RPC new

    33/60

    33

    2.6.2 How does the binding process locate the

    specified server ?

    Server Locating :

    When a client specifies the interface name of a

    server for making a RPC, the server must be

    locatedbefore the clients request message can besent to it.

    Two methods: Broadcasting

    Binding Agent

  • 8/2/2019 RPC new

    34/60

    Broadcasting:

    In this method, a message to locate the desired server is

    broadcast to all the nodes The nodes on which the desired server is located return a

    response message

    The desired server may be replicated on several nodes, so

    the client node will receive a response from all thesenodes.

    Normally, the first response that is received at the clients

    node is given to the client process & all the subsequent

    responses are discarded

    34

  • 8/2/2019 RPC new

    35/60

    Advantage:

    Easy to implement

    Suitable for small networks

    Disadvantage:

    Expensive for large networks.because of

    the increase in message traffic due toinvolvement of all nodes in the broadcasting

    process.

    35

  • 8/2/2019 RPC new

    36/60

    Binding Agent:

    It is a name server used to bind a client to a server

    by providing the client with the locationinformation of the desired server.

    A binding agent maintains a binding table , which

    is mapping of a servers interface name to its

    locations.

    All the servers register themselves as a part of

    their initialization process.

    To register with the binding agent, a server givesthe binder its identification information& a handle

    used to locate it.

    36

  • 8/2/2019 RPC new

    37/60

    A server can also deregister with the binding

    agent when it is no longer prepared to offerservice.

    The binding agent can even poll the servers

    periodically , automatically deregistering any

    server that fails to respond

    37

  • 8/2/2019 RPC new

    38/60

    Locating process:

    To locate a server, a client contacts the bindingagent..lookup

    If the server is registered with the agent, it

    returns the handle of the server to the client.

    To begin with, the binding agents location is

    known to all the nodes.

    38

  • 8/2/2019 RPC new

    39/60

    39

    Binding Agent

    Server processClient process

  • 8/2/2019 RPC new

    40/60

    Advantages:

    This method can support multiple servers having the

    same interface type so that any of the availableservers may be used to service the clients request

    This helps to achieve a degree of fault tolerance.

    Since the bindings are done by the binding agent,

    when multiple servers provide the same service, theclients can be spread evenly over the servers to

    balance the load.

    The binding mechanism can be extended to allowthe servers to specify the list of clients who may use

    its service.

    40

  • 8/2/2019 RPC new

    41/60

    Disadvantages:

    The overhead involved in binding clients to servers is large

    & becomes significant when many client processes are shortlived.

    It is necessary that the binding agent should be robust

    against failures & should not become a performance

    bottleneck. Distributing the binding function among several binding

    agents & replicating information among them can satisfy

    both these criteria.

    But, replication involves extra overhead of keeping themultiple replicas consistent.

    Hence, the functionality offered by many binding agents

    is lower than what is expected.

    41

  • 8/2/2019 RPC new

    42/60

    42

    2.6.3 When is it proper to bind a client to a server?

    Binding Time:

    A client may be bound to the server at

    Compile time

    Link time

    Call time

  • 8/2/2019 RPC new

    43/60

    Binding at Compile time:

    Here, the client and server are programmed as ifthey were intended to be linked together.

    E.g. the servers network address can be

    compiled into the client code by the

    programmer and then it can be found bylooking up the servers name in a file.

    43

  • 8/2/2019 RPC new

    44/60

    Binding at Link time:

    In this method, a server process exports its service

    by registering itself with the binding agent as partof initialization process.

    A client then makes an import request to the

    binding agent for the service before making a call.

    The binding agent binds the client & server by

    returning to the client the servers handle.

    44

  • 8/2/2019 RPC new

    45/60

    Binding at call time:

    In this method, a client is bound to a server at the

    time when it calls the server for the first timeduring its execution.

    A commonly used approach for binding at call

    time is indirect call method

    45

  • 8/2/2019 RPC new

    46/60

    46

    Binding Agent

    Server processClient process

  • 8/2/2019 RPC new

    47/60

    47

    2.6.4 Is it possible for a client to change a binding

    during execution ?

    Changing bindings: Basically, Binding is a connection establishment

    between a client & a server.

    The client or server of a connection may wish to

    change the binding at some instance due to somereason For e.g. A client getting service from a server can

    change the binding to another server of the same typewhen a call to already connected server fails.

    The server of a binding may want to alter the binding& connect the client to another server when the serviceneeds to move to another node.

  • 8/2/2019 RPC new

    48/60

    48

    2.6.5 Can a client be simultaneously bound to multiple

    servers that provide the same service ?

    Multiple simultaneous bindings:

    In a system, a service may be provided by multiple

    servers.

    Also, a client is bound to a single server out of a numberof servers.

    But, there may be situations when it is advantageous for a

    client to be bound simultaneously to all or multiple servers

    of the same type.

  • 8/2/2019 RPC new

    49/60

    Binding of this sort gives rise to multicast communication

    as all the servers bound to the client for that service will

    receive and process the call.

    E.g. a client may wish to update multiple copies of a file that isreplicated at several nodes.

    For this, the client can be bound simultaneously to all the nodes

    where the replica of the file is located.

    49

  • 8/2/2019 RPC new

    50/60

    50

    2.7 RPC Semantics in case offailure:

    The goal of RPC is to hide the communication bymaking remote calls look just like local ones.

    But, when an error occurs, the differences

    between the local & remote calls become difficult

    to mask.

    Failure handling code is a part ofRPC Runtimemechanism.

  • 8/2/2019 RPC new

    51/60

    51

    Five different classes of failure :

    1. The client is unable to locate the server.

    2. The request message from the client to server is

    lost.

    3. The reply message from server to client is lost.

    4. The server crashes after receiving a request.

    5. The client crashes after sending a request.

  • 8/2/2019 RPC new

    52/60

    52

    2.7.1. The client is unable to locate the

    server

    Solution .

    Adding a new error typecannot locate

    server

  • 8/2/2019 RPC new

    53/60

    53

    2.7.2. The request message from the clientto server is lost.

    To deal with this problem, kernel can be designedto start a TIMER when sending a request.

    If the timer expires before a reply or acknowledgecomes back, the kernel sends the message again

    Two possibilities: If the message was actually lost, the server is unable to

    identify retransmission.

    Kernel gives up after a number of tries and concludesthatthe server is down.

  • 8/2/2019 RPC new

    54/60

    54

    2.7.3 The reply message from server to

    client is lost.

    More difficult scene. Clients kernel may not understand what is the exact

    problem

    Whether request is lost, or reply is lost, or the server is slow.

    Some operations can be safely repeated without causing

    any harm..Idempotent operations

    E.g. Reading data from a file

    Consider an example of transferring money in banking

    server..Non idempotent operationas repeating the

    operation will harm the data.

  • 8/2/2019 RPC new

    55/60

    55

    One way of solving this problem is structure all the

    requests in an Idempotent way.

    not possible for all requests, like banking.

    Another way is to have the clients kernel assign eachrequest a sequence no. same request is retransmitted

    with same sequence no. if there is no problem from the

    server side , then it can understand the retransmission , &

    can refuse to carry out the request second time.

    2 7 4 Th h ft i i t

  • 8/2/2019 RPC new

    56/60

    56

    2.7.4. The server crashes after receiving a request.

    ReceiveExecute

    Reply

    Req

    Rep

    Normal Case

    ReceiveExecuteCrash

    Req

    No RepCrash after exec.

    Receive

    Crash

    Req

    No Rep

    Crash before exec.

  • 8/2/2019 RPC new

    57/60

    57

    At least once semantics.

    At most once semantics.

    Guarantee nothing

    2.7.5 The client crashes after sending a

  • 8/2/2019 RPC new

    58/60

    58

    2.7.5 The client crashes after sending a

    request.

    In this scene, the client sends a request to theserver & crashes before the server replies.

    At this point, the computation is active and no

    parent is waiting for the result.such

    unwanted computation is called ORPHAN

    Dealing with orphans:

  • 8/2/2019 RPC new

    59/60

    59

    Dealing with orphans:

    Extermination:

    Before a client stub sends a request, it makes a log entry.

    After the reboot, the log is checked & the orphan is explicitly

    killed off. This solution is called Extermination

    Reincarnation:

    This scheme divides the time up into sequentially numberedepochs.

    When a client reboots, it broadcasts a message to all the machines

    declaring the start of a new epoch.

    When such a broadcast comes in, all the remote computations are

    killed.

  • 8/2/2019 RPC new

    60/60

    60

    Gentle reincarnation:

    When an epoch broadcast comes in, eachmachine checks to see if it has any remote

    computations, & if so, tries to locate theirowner.

    Only if the owner can not be fund, is thecomputation is killed.

    Expiration:

    Here, each RPC is given a standard amount oftime T, to do the job.

    If not finished within time, RPC is expired.