Your SlideShare is downloading. ×
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Cp7 rpc
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
140
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Concurrent Programming— Slide Set 7. RPC and RMI Theodore NorvellRemote Procedure Call • Suited for Client-Server structure. • Combines aspects of monitors and synchronous message passing: ∗ Module (remote object) exports operations, invoked with call. ∗ call blocks (delays caller) until serviced. • call causes a new thread to be created on remote (server). • Client-server synchronization and communication is implicit.c°2003, 2005 — Typset March 5, 2008 1
  • 2. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Terminology / Notationserver module: operations, (shared) variables, localprocedures and threads for servicing remote procedurecalls.interface (specification): describes the operations, parametertypes and return types.op opname(param types) [returns return type]server process: thread created by call to service an operation.background process: threads running in a module that aren’tcreated in response to call.c°2003, 2005 — Typset March 5, 2008 2
  • 3. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Example Server Modulemodule TicketServer op getNext returns int ;body int next := 0 ; sem ex := 1 ; procedure getNext() returns val { P(ex) ; val := next ; next := next + 1 ; V(ex) ; }end TicketServerc°2003, 2005 — Typset March 5, 2008 3
  • 4. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Issues Lookup and registrationHow does the client find the server?Often server registers (binds) with a naming service (registry).Client obtains information (lookup) about server from thisserver.This changes the question to: How does the client find theregistry? SynchronizationSynchronization within a module (server). Two approaches:1. Assume mutual exclusion in server (only one server process/background process executing at a time). ∗ Similar to monitors. ∗ Still need conditional synchronization.2. Program it explicitly (i.e., using semaphores, monitors etc.).c°2003, 2005 — Typset March 5, 2008 4
  • 5. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Argument passingFormats may be different on different machines. • ints are different sizes, encodings, endianess. • floats have different encodingsAddress space is different in different processes. • Can not pass pointers. • Can not pass by reference. • Can not pass objects containing pointers.Three solutions: • Copy-in: Arguments are converted to byte arrays (serializa- tion) and reconstructed on the other side. • Copy-in/copy-out: Copy-in + final value is passed back. • Proxy objects: A proxy object is constructed on the server side. Calls to the proxy are converted to RPCs back to the argument.c°2003, 2005 — Typset March 5, 2008 5
  • 6. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Java RMI (Remote Method Invocation)Client objects and server objects are local to different JVMprocesses.Server objects (usually) extendjava.rmi.server.UnicastRemoteObject. Lookup and registrationHow does the client find the server?• Server objects registered by name with a registry service. (Naming.bind) • Client objects obtain references to proxy objects from the registry service. (Naming.lookup) SynchronizationSynchronization within a module (server). • Each remote call implies the creation of a new server thread. So if there are multiple clients, there can be multiple server threads active at the same time. • Synchronization must be programmed explicitly (use synchronized or my monitor package)c°2003, 2005 — Typset March 5, 2008 6
  • 7. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Argument passingFormats may be different on different machines. • Not an issue as data formats are standard across all Java implementations.Address space is different in different processes. • Reference arguments (and subsidiary references) are serialized and passed by copy-in rather than by reference. • Except RemoteObjects, in which case a proxy (‘stub’) is passed instead (This complicates garbage collection).c°2003, 2005 — Typset March 5, 2008 7
  • 8. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell Skeletons and Stubs • ‘Stub’ objects implement the same interface as the server objects. (Proxy pattern) • (0), (5) Client threads call a stub local to their JVM instance. • (1), (4) Stub messages (TCP/IP) to Skeleton object in remote JVM & waits for reply. • (2), (3) Skeleton creates a new server thread which calls the server. • Stub and skeleton classes are synthesized by a RMI Com- piler (rmic). Call Return Client Server Message (0) (3) (5) (2) Stub Object Skeleton (Proxy) Process (JVM) (1) (4) Networkc°2003, 2005 — Typset March 5, 2008 8
  • 9. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell ExampleStart a registry processD:...classes> rmiregistry -Jcp -J.First we need an interface for the serverpackage tryrmi;import java.rmi.* ;public interface TicketServerInterface extends Remote{ public int getTicket() throws RemoteException ; }c°2003, 2005 — Typset March 5, 2008 9
  • 10. Concurrent Programming— Slide Set 7. RPC and RMI Theodore NorvellWe implement the interface and write a main program to createand register the server object.package tryrmi;import java.rmi.*;import java.rmi.server.UnicastRemoteObject;public class TicketServerextends UnicastRemoteObjectimplements TicketServerInterface { private int next = 0 ; public synchronized int getTicket() throws RemoteException { return next++ ; } public TicketServer() throws RemoteException { super() ; }c°2003, 2005 — Typset March 5, 2008 10
  • 11. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvell public static void main( String[] args ) { try { TicketServer server = new TicketServer() ; String name = args[0] ; Naming.bind( name, server ) ; } catch( java.net.MalformedURLException e) { ... } catch( AlreadyBoundException e) { ... } catch( RemoteException e ) { ... } } }Executing main creates and registers a server object.D:...classes> java -cp . tryrmi.TicketServer rmi://frege.engr.mun.ca/ticketThe skeleton object will be generated automatically by theJava Runtime Environment. (There is no need to write a classfor the skeleton object.)Some client codepackage tryrmi;c°2003, 2005 — Typset March 5, 2008 11
  • 12. Concurrent Programming— Slide Set 7. RPC and RMI Theodore Norvellimport java.rmi.* ;public class TestClient { public static void main(String[] args) { try { String name = args[0] ; TicketServerInterface proxy = (TicketServerInterface) Naming.lookup( name ) ; use proxy object} catch( java.net.MalformedURLException e) { ... } catch( NotBoundException e) { ... } catch( RemoteException e) { ... } } }The client can be executed from anywhere on the internet. (Thestub object will be created by the Java Runtime Environment.There is no need to write a class for the stub object.)D:...classes> java -cp . tryrmi.TestClient rmi://frege.engr.mun.ca/ticketc°2003, 2005 — Typset March 5, 2008 12
  • 13. Concurrent Programming— Slide Set 7. RPC and RMI Theodore NorvellRPC 6= PCAlthough remote procedure calls and local procedure calls arebeguilingly similar and in Java share exactly the same syntax,there are important differences • Partial Failure ∗ Part of the system of objects may fail ∗ Partial failures may be intermittent ∗ Network delays · On a large network, delays are indistinguishable from failures • Performance ∗ Remote calls are several orders of magnitude more expensive than local calls (100,000 or more to 1) • Concurrency ∗ Remote calls introduce concurrency that may not be in a nondistributed system. • Semantics changes ∗ In Java, local calls pass objects by reference. ∗ Remote calls pass objects either by copy or by copying a proxy.c°2003, 2005 — Typset March 5, 2008 13

×