720 likes | 740 Views
Communication. Chapter 2. Communication. Layered protocols Usual networking approach (client/server) Remote Procedure Call (RPC) Hide message passing details (client/server) Remote Method Invocation (RMI) Improved RPC (client/server). Communication. Message-Oriented Communications
E N D
Communication Chapter 2 Chapter 2 Communication 1
Communication • Layered protocols • Usual networking approach (client/server) • Remote Procedure Call (RPC) • Hide message passing details (client/server) • Remote Method Invocation (RMI) • Improved RPC (client/server) Chapter 2 Communication 2
Communication • Message-Oriented Communications • Message Passing Low level, efficient • Message-Oriented Middleware (MOM) Non client/server • Streams • Continuous flow subject to timing constraints Chapter 2 Communication 3
Layered Protocols • OSI reference model • Each layer provides service to layer above • Implementation of service can change Chapter 2 Communication 4
Layer Services • Transport layer • Logical connection between hosts • Reliable communication between hosts • Network layer • Route packet thru network • Data link layer • Get packet over each hop • Physical layer • Put the bits on the “wire” Chapter 2 Communication 5
Layered Protocols • Layered message • Add headers when msg sent (down protocol stack) • Peel the onion when msg received (up the protocol stack) Chapter 2 Communication 6
Data Link Layer • Communication at data link layer • Above, A tries to send msgs 0 and 1 to B Chapter 2 Communication 7
Network Layer • On a LAN • Have a shared media • Put the packet out, recipient picks it up • On a WAN • Have point-to-point communication • Many possible routes • Finding best route is difficult Chapter 2 Communication 8
Transport Layer • UDP for unreliable delivery • Better performance possible with UDP • TCP for reliable delivery • May be easier to build app with TCP Chapter 2 Communication 9
Client-Server TCP Normal TCP Transactional TCP Chapter 2 Communication 10
Middleware Protocols • Reference model for middleware based distributed communication Chapter 2 Communication 11
What is Middleware? • Logically at application layer • General purpose protocols • Independent of an application • We’ll distinguish between • High level application and • Middleware Chapter 2 Communication 12
Middleware Example • Often, must authenticate users • Require users prove identity • Spse you build authentication system • Any app can use your auth system • Your authentication “application” • Is at application layer in OSI • Is also at middleware layer in our view Chapter 2 Communication 13
Middleware • Remainder of this chapter • 4 middleware communication services • RPC • RMI • Message oriented communication • Streaming Chapter 2 Communication 14
Remote Procedure Call • Distributed systems can be built on explicit message passing • For example, send and receive • What’s wrong with this approach? • It’s not transparent to users • Why should we care? • Recall that transparency is one of primary goals in distributed systems Chapter 2 Communication 15
Remote Procedure Call • RPC is a simple idea • Make remote operation seem like a (local) procedure call • “All the great things are simple” Winston Churchill • Much better transparency compared to primitive message passing • Can we make remote operation seem local? Chapter 2 Communication 16
Conventional Procedure Call • Stack before call to read • Stack while called procedure is active • Consider C function: count = read(fd, buf, bytes) Chapter 2 Communication 17
Parameter Passing • Consider again • C function: count = read(fd, buf, bytes) • In C, parameters can be • Passed by value: bytes • Passed by reference: the array buf • Usually not important whether pass by value or pass by reference is used • But it’s a big deal in RPC! • Since procedure will execute at remote location Chapter 2 Communication 18
RPC between Client/Server • We say that this is synchronous • Since client waits for result Chapter 2 Communication 19
Stubs • On client side, stub marshalls parameters and send to server • Pack parameters into message(s) • On server side, stub converts to local procedure call, sends back results • Stubs increase transparency Chapter 2 Communication 20
Passing Value Parameters • Suppose add(i,j) returns i + j • Remote computation via RPC Chapter 2 Communication 21
Client Stub • Procedure • Stub marshalls params Chapter 2 Communication 22
Steps in RPC • Client procedure calls client stub in normal way • Client stub builds message, calls local OS • Client's OS sends message to remote OS • Remote OS gives message to server stub • Server stub unpacks parameters, calls server • Server does work, returns result to the stub • Server stub packs it in message, calls local OS • Server's OS sends message to client's OS • Client's OS gives message to client stub • Stub unpacks result, returns to client Chapter 2 Communication 23
Additional RPC Topics • Doors • Caller and sender on same machine • Asynchronous RPC • Client does something while server works on procedure • DCE RPC • Specific implementation of RPC Chapter 2 Communication 24
Doors • If client and server on same machine • Use interprocess communication (IPC) • More efficient than network protocols Chapter 2 Communication 25
The Doors • Doors are not to be confused with “The Doors” Chapter 2 Communication 26
Asynchronous RPC • Usual (synchronous) RPC • Asynchronous RPC Chapter 2 Communication 27
Asynchronous RPC • Client and server interact via two asynchronous RPCs • More efficient, if applicable Chapter 2 Communication 28
DCE RPC • Distributed Computing Environment (DCE) • Read this section • A couple of interesting items… • DCE semantic options • At-most-once no call done more than once, even if system crash • Idempotent calls can be repeated multiple times (e.g., read) Chapter 2 Communication 29
DCE RPC • Client-to-server binding in DCE • Note directory service Chapter 2 Communication 30
RMI • Remote Method Invocation • Distributed objects • Objects hide internals • Provides transparency • Also desirable in distributed systems • RMI can increase transparency compared to RPC • Chapter 9 has real object systems Chapter 2 Communication 31
Objects • Object encapsulates data, the state • Object encapsulates methods, operations on the data • Methods are made available thru well-defined interfaces • In distributed environment • Interface can be on one machine and • Corresponding object on another machine Chapter 2 Communication 32
Distributed Objects • Interface on client • Proxy like client stub in RPC • Object on server • Skeleton like server stub in RPC Chapter 2 Communication 33
Compile-time vs Runtime • Compile-time objects • Objects analogous to those in Java, C++ • Pluses: easy to implement • Minuses: depends on specific language • Runtime objects • Implementation is open, use adapter (wrapper) to hide implementation • Plus and minus opposite of those above Chapter 2 Communication 34
RMI and Parameter Passing • Makes sense to treat local and remote objects differently • Lots of overhead to remote objects • Pass by reference gets complicated Chapter 2 Communication 35
Java RMI • Distributed objects are an integral part of Java • Aims for high degree of transparency • For example client proxy has same interface as remote object • There are subtle differences between local and remote objects… Chapter 2 Communication 36
Java RMI • Cloning • Cloning a local object results in exact copy • Only server can clone remote object • In Java, proxies not cloned • So must bind (again) to cloned object • Can declare method to be synchronized • Ensures access to data is serialized • Blocking • Clients blocked Chapter 2 Communication 37
Java RMI • Read the details • A preview of Chapter 5… • Spse multiple clients want to access a method on server (method is synchronized) • Block all but one client lots of overhead • Block at the server what if client crashes? • Java restricts blocking to proxies • Simplifies things • But then can’t prevent simultaneous access of remote objects simply by synchronized Chapter 2 Communication 38
Message-Oriented Comm. • RPC and RMI enhance transparency • But RPC and RMI are “inherently synchronous” • Consider an email system where • Messages stored on email servers when in transit and before read • Stored locally after read • Example of persistent communication Chapter 2 Communication 39
Message-Oriented Comm. • In email example • Sender need not continue executing after sending msg • Receiver need not be executing when msg sent (to dest server) • Comparable to the Pony Express! • The more things change, the more they stay the same… Chapter 2 Communication 40
Pony Express • Persistent comm. and the Pony Express Chapter 2 Communication 41
Transient and Asynchronous • Transient • Msg is stored only as long as sender and receiver are alive • If msg can’t be delivered, discard it • Asynchronous • Sender does not wait for response before continuing • Recall persistent and synchronous • Four possible combinations… Chapter 2 Communication 42
Examples • Transient asynchronous • UDP • Transient synchronous • Synchronous RPC • Persistent asynchronous • email • Persistent synchronous • Msg can only be stored at receiving host Chapter 2 Communication 43
Persistence and Synchronicity • Persistent asynchronous communication • Persistent synchronous communication Chapter 2 Communication 44
Persistence and Synchronicity • Transient asynchronous communication • Receipt-based transient synchronous communication Chapter 2 Communication 45
Persistence and Synchronicity • Delivery-based transient synchronous communication at message delivery • Response-based transient synchronous communication Chapter 2 Communication 46
Message-Oriented Comm. • Message-oriented systems take transient asynchronous as baseline • Like UDP • But persistence sometimes needed • Especially if geographically distributed • Network or process failures likely • Message passing like transport layer Chapter 2 Communication 47
Message-Oriented Comm. • Transient • Berkeley sockets • Message Passing Interface (MPI) • Persistent • Message queuing model, MOM • Message brokers Chapter 2 Communication 48
Berkeley Sockets • Socket primitives for TCP/IP Chapter 2 Communication 49
Berkeley Sockets • Connection-oriented communication pattern using sockets • Note “synchronization point” Chapter 2 Communication 50