CSE 486/586 Distributed Systems Remote Procedure Call Recall?
Total Page:16
File Type:pdf, Size:1020Kb
Recall? App CSE 486/586 Distributed Systems Remote Procedure Call Socket API TCP UDP OS Steve Ko IP Computer Sciences and Engineering University at Buffalo Device Drivers Network Interface CSE 486/586 CSE 486/586 2 Socket API What’s Wrong with Socket API? Server • Low-level read/write socket() • Communication oriented • Same sequence of calls, repeated many times bind() • Etc, etc… Client listen() • Not programmer friendly socket() establish accept() connection connect() block send request write() read() process request send response write() read() CSE 486/586 3 CSE 486/586 4 Another Abstraction RPC • RPC (Remote Procedure Call) • Client • Server – Goal: it should appear that the programmer is calling a local function int main (…) … – Mechanism to enable function calls between different { processes – First proposed in the 80’s … void rpc_call(…) { • Examples rpc_call(…); … – Sun RPC … } – Java RMI – CORBA } • Other examples that borrow the idea … – XML-RPC – Android Bound Services with AIDL – Google Protocol Buffers CSE 486/586 5 CSE 486/586 6 C 1 Local Procedure Call Remote Procedure Call • E.g., x = local_call(“str”); • Give an illusion of doing a local call • The compiler generates coDe to transfer necessary • Closer to the programmers things to local_call – Language-level construct, not OS-level support – Push the parameters to the stack • What are some of the challenges? – Call local_call – How do you know that there are remote calls available? • The compiler also generates coDe to execute the – How do you pass the parameters? local call. – How do you find the correct server process? – Assigns registers – How do you get the return value? – AdJust stack pointers – Saves the return value – Calls the return instruction CSE 486/586 7 CSE 486/586 8 Stub, Marshalling, & Unmarshalling RPC Process • Stub functions: local interface to make it appear that the call is local. Client Process Server Process • Marshalling: the act of taking a collection of data items (platform dependent) and assembling them into the external data representation (platform Client Function Server Function independent). • Unmarshalling: the process of disassembling data that is in external data representation form, into a Client Stub Server Stub locally interpretable form. Marshalling/unmarshalling Socket API Socket API CSE 486/586 9 CSE 486/586 10 Invocation Semantics Due to CSE 486/586 Administrivia Failures • Will post mid-semester grades this week • Local calls do not fail. • PA3 is due this Friday. • Remote calls might fail. • Programmers should deal with this. – No transparency here CSE 486/586 11 CSE 486/586 12 C 2 Failure Modes of RPC Invocation Semantics Request • Local procedure call: exactly-once correct lost • Remote procedure call: Execute request function – 0 times: server crashed or server process died before Reply executing server code – 1 time: everything worked well, as expected Request Channel Execute fails – 1 or more: excess latency or lost reply from server and client during retransmission Execute, crash reply before Reply Crash • When do these make sense? reply – Idempotent functions: OK to run any number of times Request Client – Non-idempotent functions: cannot do it machine Execute • What we can offer fails crash Crash before – At least once before receiving execution Reply – At most once reply CSE 486/586 13 CSE 486/586 14 Invocation Semantics How Do You Generate Stubs? • Design choices that you can make (depends on what • Ever heard of C/C++, Java, Python syntax for RPC? your server function does---idempotent or non- – None! idempotent) • Language compilers don’t generate client and server stubs. Fault tolerance measures Invocation • Common solution: use a separate language and a semantics pre-compiler Retransmit request Duplicate Re-execute procedure message filtering or retransmit reply No Not applicable Not applicable Maybe Yes No Re-execute procedure At-least-once Yes Yes Retransmit old reply At-most-once CSE 486/586 15 CSE 486/586 16 Interface Definition Language (IDL) Example: SUN XDR const MAX = 1000; struct readargs { • Allow programmers to express remote procedures, typedef int FileIdentifier; e.g., names, parameters, and return values. FileIdentifier f; typedef int FilePointer; • Pre-compilers take this and generate stubs, FilePointer position; typedef int Length; marshalling/unmarshalling mechanisms. Length length; • Similar to writing function definitions struct Data { }; int length; char buffer[MAX]; program FILEREADWRITE { }; version VERSION { struct writeargs { void WRITE(writeargs)=1; FileIdentifier f; Data READ(readargs)=2; FilePointer position; }=2; Data data; 18 } = 9999; CSE 486/586 17 }; CSE 486/586 C 3 How Do You Find the Server Stub Generation Process? • Solution 1 Compiler / Linker gcc – Central DB (the first solution proposed) Server • Solution 2 .o, .exe Program Server .c Server .c – Local DB with a well-known port (SUN RPC) Stub Source .h Interface Common RPC Stub RPC Specification Generator Header LIBRARYLIBRARY e.g., in SUN XDR e.g., rpcgen Client Client .c Client .c Stub Source .o, .exe Program Compiler / Linker gcc CSE 486/586 19 CSE 486/586 20 Local DB with Well-Known Port How to Pass Parameters? Finding An RPC: • Pass by value: no problem CLIENT – Just copy the value Client RPCs live on specific hosts at specific ports. Client Stub • What about pointers/references? Program Port mapper on the host maps – NeeD to copy the actual Data as well Network from RPC name to port# Code – Marshall them at the client anD unmarshall them at the When a server process is server initialized, it registers its RPCs – Pass the local pointers/references (handle) with the port mapper on the server • What about complex Data structures? struct, class, SERVER etc. Port Mapper A client first connects to port mapper (daemon on standard – NeeD to have a platform inDepenDent way of representing port) to get this handle data Server The call to RPC is then made Server procedure by connecting to the Stub corresponding port CSE 486/586 21 CSE 486/586 22 Example: Remote Method Invocation External Data Representation (RMI) • Commonly called serialization • Communication between two heterogeneous Process P1 (client) Process P2 (server) machines – Different byte ordering (big-endian & little-endian) client server remote skeleton – Different sizes of integers and other types object A proxy for B object B Request & dispatcher – Different floating point representations for B's class – Different character sets – Alignment requirements Reply • Used in general contexts, not just in RPCs Remote Communication Communication Remote reference • Many protocols exist reference module module module module – Java serialization, Google ProtoBuf, etc. CSE 486/586 23 CSE 486/586 24 C 4 Summary Acknowledgements • RPC enables programmers to call functions in • These slides contain material developed and remote processes. copyrighted by Indranil Gupta (UIUC). • IDL (Interface Definition Language) allows programmers to define remote procedure calls. • Stubs are useD to make it appear that the call is local. • Semantics – Cannot proviDe exactly once – At least once – At most once – DepenDs on the application requirements CSE 486/586 25 CSE 486/586 26 C 5.