150 likes | 265 Views
This document explores the essential concepts of Remote Procedure Calls (RPC) in network systems. It compares RPC with local function calls, highlighting how the request-response model operates. Key aspects include the roles of client and server stubs in message handling and the challenges posed by pointer passing in RPC, especially concerning memory access. The importance of consistent data representation across different machines and error handling in network calls is also discussed. Practical examples, including a remote calculator program, illustrate these concepts in real-world applications.
E N D
CPS110: More Networks Landon Cox March 27, 2008
Network abstractions • We’ve been using send/receive • Client sends a request to the server • Server receives request • Server sends response to client • What else in CS is this interaction like? • Calling a function
Remote procedure call (RPC) • RPC makes request/response look local • Provide a function call abstraction • RPC isn’t a really a function call • In a normal call, the PC jumps to the function • Function then jumps back to caller • This is similar to request/response though • Stream of control goes from client to server • And then returns back to the client
RPC stub functions • Key to making RPC work • Stub functions
RPC stub functions call send Client stub recv return send return Server stub call recv
RPC stub functions • Client stub 1) Builds request message with server function name and parameters 2) Sends request message to server stub • (transfer control to server stub) 8) Receives response message from server stub 9) Returns response value to client • Server stub 3) Receives request message 4) Calls the right server function with the specified parameters 5) Waits for the server function to return 6) Builds a response message with the return value 7) Sends response message to client stub
RPC example • Client calls produce(5) Client stub: Server stub: // must be named produce! int produce (int n) { int status; send (sock, &n, sizeof(n)); recv (sock, &status, sizeof(status)); return status; } // could be named anything void produce_stub () { int n; int status; recv (sock, &n, sizeof(n)); // produce func on server! status = produce (n); send (sock, &status, sizeof(status)); } Server stub code can be generated automatically (C/C++: rpcgen, Java: rmic) What info do you need to generate the stubs? Input parameter types and the return value type.
Java RMI example • Remote calculator program
Problems with RPC • How is RPC different from local function calls? • Hard to pass pointers (and global variables) • What happens if server dereferences a passed-in pointer? • Pointer will access server’s memory (not client’s) • How do we solve this? • Send all data reachable from pointer to the server • Change the pointers on the server to point to the copy • Copy data back when server function returns
Example RPC with pointers • On client: int a[100]; • Want to send “a” (a pointer to an array) • Copy entire array to server • Have server’s pointer point to copy of a • Copy array back to client on return • What if a is more complicated? A linked list? • Have to marshal the transitive closure of pointer
Problems with RPC • Data may be represented differently • Machines have different “endianness” • Byte 0 may be least or most significant • Must agree on standard network representation • RPC has different failure modes • Server or client can fail during a call • In local case, client and server fail simultaneously
Finishing RPC • Where have you used RPC in CPS 110? • Project 2 infrastructure • C library interface to system calls is similar • Makes something look like a function call
Structuring a concurrent system • Talked about two ways to build a system
Alternative structure • Can also give cooperating threads an address space • Each thread is basically a separate process • Use messages instead of shared data to communicate • Why would you want to do this? • Protection • Each module runs in its own address space • Reasoning behind micro-kernels • Each service runs as a separate process • Mach from CMU (influenced parts Mac OS X) • Vista’s handling of device drivers
Course administration • Project 2 scores (out of 89) • 88, 86, 86, 86, 86, 84, 84, 84, 84, 71, 66, 50 • Great! • Project 3 out next week (I hope) • Questions?