implementing remote procedure calls

32
Implementing Remote Procedure Calls Andrew Birrell and Bruce Nelson Slide Set by Phil Howard and others

Upload: zeph-mcdonald

Post on 03-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

Implementing Remote Procedure Calls. Andrew Birrell and Bruce Nelson. Slide Set by Phil Howard and others. Why?. Consider. #include int main() { printf("hello world!\n"); return 0; }. What Happens. main. main. printfglibc. kernel IOkernel. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Implementing Remote Procedure Calls

Implementing Remote Procedure Calls

Andrew Birrell and Bruce Nelson

Slide Set by

Phil Howard and others

Page 2: Implementing Remote Procedure Calls

Why?

Page 3: Implementing Remote Procedure Calls

Consider

#include <stdio.h>int main(){

printf("hello world!\n");return 0;

}

Page 4: Implementing Remote Procedure Calls

What Happens

main

printf glibc

main

kernel IO kernel

update_window X

update_display

kernel IO kernel

Page 5: Implementing Remote Procedure Calls

But what if

X Server

Console Window

main

Linux BoxX Client

Laptop

Page 6: Implementing Remote Procedure Calls

What Happens

main

printf glibc

main

kernel IO kernel

update_window X

update_display

Linux BoxX Client

update_display X

kernel IO kernel

Laptop

Page 7: Implementing Remote Procedure Calls

How do you do this?

• Fork/Join?

• SendMessage/AwaitReply?

• Virtual Shared Memory?

• Remote Procedure Call?

Page 8: Implementing Remote Procedure Calls

Remote Procedure Call (RPC)

Page 9: Implementing Remote Procedure Calls

What's Involved in RPC

• Remote Procedure Call should look and feel like local call

• Remote Procedure Call should be independent of where it executes

• Remote Procedure Call should be "efficient"

Page 10: Implementing Remote Procedure Calls

Issues

• Finding the callee• Passing data• Implementation• Exceptions• Optimizations

Page 11: Implementing Remote Procedure Calls

Finding the Callee(Binding)

• Where- Either server has known static address- Or client broadcasts request- Or use central database of interfaces

• What- Servers export named interfaces- Clients request a particular interface- Need Globally Unique Identifiers for interfaces

Page 12: Implementing Remote Procedure Calls

• Type

- Like object oriented programming interfaces

- Method names, parameter and result types

- Underlying functionality is hidden

Instance

- Which specific provider of this type

Interfaces

Page 13: Implementing Remote Procedure Calls

Binding

• Callee exports an interface via a network accessible database.

Database

RPCRuntime

UpdateDatabase

Server Stub Server

ExportInterface

ExportInterface

Callee

Page 14: Implementing Remote Procedure Calls

Binding

• Caller binds by specifying the type of the interface in a database query

• Selects from a list of instances returned

Caller

RPCRuntimeUser StubUser

ImportInterface

ImportInterface

QueryDatabase

InterfaceInfo

InterfaceInfo

InterfaceInfo

Database

Who’s available?

AvailableInterfaces

Page 15: Implementing Remote Procedure Calls

Issues

• Finding the callee

• Passing data• Implementation• Exceptions• Optimizations

Page 16: Implementing Remote Procedure Calls

Passing Data

• Can't use the stack!

• Can't use shared memory!

• Generally use message passing

Page 17: Implementing Remote Procedure Calls

Passing Data#include <stdio.h>int main(){

union{

unsigned long stuff1;unsigned char stuff2[4];

} my_var;

my_var.stuff1 = 0x12345678;

printf("%X %X %X %X\n", my_var.stuff2[0], my_var.stuff2[1],my_var.stuff2[2], my_var.stuff2[3]);

return 0;

}

Page 18: Implementing Remote Procedure Calls

Passing Data

What's the output?

12 34 56 78

or

78 56 34 12

Page 19: Implementing Remote Procedure Calls

Passing data

Build a message that includes:• Who and what's being called• Identity of the caller• Data values in known byte order

• Using an intermediate data representation

Page 20: Implementing Remote Procedure Calls

Issues

• Finding the callee• Passing data

• Implementation• Exceptions• Optimizations

Page 21: Implementing Remote Procedure Calls

Implementation

foo(a,&b) foo(int a, int *b)

return;

Page 22: Implementing Remote Procedure Calls

Implementation

foo(int a; int *b){

build_msg(a,b);send_msg();wait_for_reply();get_from_msg(&b);

}

do_foo(msg_t msg){

int a,b;get_from_msg(&a,&b);foo(a,&b);build_msg(b);send_reply();

}

Page 23: Implementing Remote Procedure Calls

Implementation

• Function prototype is (almost) all that's needed to build the client stub– Also need binding information

• Function prototype is (almost) all that's needed to build server stuff– Also need method to wait for message

Page 24: Implementing Remote Procedure Calls

ImplementationCaller

RPCRuntime

Transmit packet(s)

Receive packet(s)

Send packet

NetworkNetwork

NetworkNetwork

Receive packet

User StubUser

Procedure call

procedure return

Packarguments

Unpackresult(s)

Callee

RPCRuntime

Receivepacket(s)

Transmitpacket(s)

Server Stub Server

Procedure call

Procedure return

Unpackarguments

Packresult(s)

Receive packet

Send packet

Page 25: Implementing Remote Procedure Calls

Implementation

Clients

Threaded

Servers

Event Driven

Page 26: Implementing Remote Procedure Calls

Issues

• Finding the callee• Passing data• Implementation

• Exceptions• Optimizations

Page 27: Implementing Remote Procedure Calls

Exceptions

• What can happen in "normal" procedures? – Procedure generates an exception– Procedure infinite loops– Procedure generates wrong results

Page 28: Implementing Remote Procedure Calls

Exceptions

• What can happen in "remote" procedures? – Client stub generates exception– Transmission failure

knowable failure unknowable failure

– Remote procedure generates an exception– Remote procedure infinite loops– Remote procedure generates wrong results

Page 29: Implementing Remote Procedure Calls

Issues

• Finding the callee• Passing data• Implementation• Exceptions

• Optimizations

Page 30: Implementing Remote Procedure Calls

Optimizations

• Servers maintain no state on clients– No penalty for a large number of clients

• Messages must be ack'd– for short calls, result serves as ack

– for frequent calls, next call ack's last result

– for long requests, only last request message gets ack'd

– for long results, only last result message gets ack'd

• Bound to "closest" server– Minimum transmission delay

Page 31: Implementing Remote Procedure Calls

Protocol-Level OptimizationsCaller

RPCRuntime

Transmit first packet

Receiveresult

User

Procedure call

procedure return

Callee

Server

Procedure call

procedure return

RPCRuntime

Call[Ids, packet=0]

Ack[Ids, packet=0]

Call[Ids, packet=1]Transmit next packet

Transmit ack

Receivepacket 0

Receivepacket 1

Receive ack

Retransmit next packet

Call[Ids, packet=1, needAck] Receivepacket 1

Transmit ackAck[Ids, packet=1]

Receive ack

Transmitresult

Transmit ackrequest

Result[Ids]

Result[Ids, needAck]Receiveresult

Transmit ackAck[Ids]

Receive ack

Page 32: Implementing Remote Procedure Calls

Conclusion

• Remote Procedure Call should look and feel like local call

• Remote Procedure Call should be independent of where it executes

• Remote Procedure Call should be "efficient"