CS162 Operating Systems and Systems Programming Lecture 22 Client Server April 18 2011 Ion Stoica http inst eecs berkeley edu cs162 Distributed Systems are Everywhere We need want to share physical devices e g printers and information e g files Many applications are distributed in nature e g ATM machines airline reservations Many large problems can be solved by decomposing smaller problems that run in parallel e g MapReduce SETI home Next three lectures go over three distributed system models 4 18 Client server Peer to peer Cloud cluster computing Ion Stoica CS162 UCB Spring 2011 Lec 22 2 Client Server One or more clients interacting with one or more servers providing a service e g Web E mail chat Printer Airline reservation On line shopping Store streaming video audio and or photos In this lecture End to end message communication Remote Procedure Calls Two phase commit transactions World Wide Web 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 3 Message Passing Process A e g client sends a packet to process B e g server Proc A port 10 Internet 128 15 11 12 16 25 31 10 4 18 Proc B port 7 Ion Stoica CS162 UCB Spring 2011 Lec 22 4 Message Passing Details Proc A port 10 Internet 16 25 31 10 Proc A port 10 Transport Network Datalink Physical 16 25 31 10 4 18 data Proc B port 7 128 15 11 12 Proc B port 7 data data 10 7 data 10 7 data 10 7 16 25 31 10 128 15 11 12 data 10 7 16 25 31 10 128 15 11 12 Internet Ion Stoica CS162 UCB Spring 2011 Transport Network Datalink Physical 128 15 11 12 Lec 22 5 From Message Passing to Remote Procedure Call Raw messaging is a bit too low level for programming Another option Remote Procedure Call RPC Looks like a local procedure call on client Translated automatically into a procedure call on remote machine server Implementation Uses request response message passing under the covers 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 6 Example Local Procedure Call Machine Process n sum 4 7 4 18 sum i j int i j return i j Ion Stoica CS162 UCB Spring 2011 Lec 22 7 Remote Procedure Call Transparently invoke a procedure services implemented in a different address space either on the same machine or a different machine Services can be run wherever it s most appropriate Access to local and remote services looks the same Challenges Argument parameter passing potentially across different architectures Discover where the service is located Handle failures transparently 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 8 RPC Argument Passing Client and server use stubs to glue pieces together Client side stub is responsible for marshalling arguments and unmarshalling the return values Server side stub is responsible for unmarshalling arguments and marshalling the return values Marshalling involves depending on system converting values to a canonical form serializing objects copying arguments passed by reference etc Needs to account for cross language and cross platform issues Technique compiler generated stubs Input interface definition language IDL Contains among other things types of arguments return Output stub code in the appropriate source language 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 9 RPC Information Flow call return Machine B Server callee 4 18 return call unbundle ret vals bundle ret vals Server Stub unbundle args send receive Packet Handler send receive Ion Stoica CS162 UCB Spring 2011 Network Machine A Client Stub Network Client caller bundle args Packet Handler Lec 22 10 Example Remote Procedure Call Stubs Client Server Process n sum 4 7 Process message sum 4 7 message sum 4 7 OS 4 18 sum i j int i j return i j OS Ion Stoica CS162 UCB Spring 2011 Lec 22 11 Client and Server Stubs Principle of RPC between a client and server program 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 12 Encoding Server and client may encode arguments differently e g Big endian store from most to least significant byte Little endian store from least to most significant byte a Original message on x86 e g little endian b The message after receipt on the SPARC e g big endian c The message after being inverted The little numbers in boxes indicate the address of each byte 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 13 Parameter Specification and Stub Generation a b 4 18 A procedure The corresponding message Ion Stoica CS162 UCB Spring 2011 Lec 22 14 Service Discovery RPC Binding How does client know which machine to send RPC Need to translate name of remote service into network endpoint e g host port Binding the process of converting a user visible name into a network endpoint Static fixed at compile time Dynamic performed at runtime Dynamic Binding Most RPC systems use dynamic binding via name service Why dynamic binding Access control check who is permitted to access service Fail over If server fails use a different one 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 15 Example of RPC Binding Distributed Computing Environment DCE framework DCE daemon Allow local services to record their services locally Resolve service name to local end point i e port Directory machine resolve service name to DCE daemon host port on machine running the service 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 16 RPC Semantics in the Presence of Failures The client is unable to locate the server The request message from the client to server is lost The reply message from the server is lost The server crashes after receiving a request The client crashes after sending a request 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 17 Client is Unable to Locate Server Causes server down different version of server binary Fixes Return 1 to indicate failure in Unix use errno to indicate failure type What if 1 is a legal return value Use exceptions Transparency is lost 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 18 Lost Request Message Easiest to deal with Just retransmit the message If multiple message are lost then client is unable to locate server error 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 19 Lost Reply Message Far more difficult to deal with client doesn t know what happened at server Did server execute the procedure or not Possible fixes Retransmit the request Only works if operation is idempotent it s fine to execute it twice What if operation not idempotent Assign unique sequence numbers to every request 4 18 Ion Stoica CS162 UCB Spring 2011 Lec 22 20 Server Crashes Three cases Crash after execution Crash before execution Crash during the execution Three possible semantics At least once semantics Client
View Full Document
Unlocking...