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