Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remote Procedure Call and Remote Method Invocation INF 123 – Software architecture 1.

Similar presentations


Presentation on theme: "Remote Procedure Call and Remote Method Invocation INF 123 – Software architecture 1."— Presentation transcript:

1 Remote Procedure Call and Remote Method Invocation INF 123 – Software architecture 1

2 Outline RPC theory Sun RPC XML RPC RMI 2

3 RPC: THEORY 3

4 The Problem 1980s: Internet and web servers How can a client make a server do something? – Sockets are used to transmit data, not functions – Sending function code as text is a bad idea Client in Python, server in C#? Server runs eval(evil_code)? Eval is evil … 4

5 Dr. Eval 5 eval(readline()), eval(message), …

6 Reminder: main and subroutines Main calls subroutines Subroutines return values Subroutines have no side-effects AKA “call and return” “Not a real architecture” <- really? Why? 6

7 RPC Transparently call a procedure located in another process or machine “make the invocation of a procedure on a remote machine appear as though it were local” ml ml 7

8 Solution: RPC 8 r = foo(a, b) define foo(a, b) … end caller callee program host Local Procedure Calls r = foo(a, b) define foo(a, b) … end caller callee program host 1 host 2 program Remote Procedure Calls Caller stub Callee stub

9 RPC with words The local procedure calls a caller stub The caller stub serializes the call (function name + arguments) and sends it to the callee stub on a remote machine The callee stub calls the remote procedure The remote procedure does its job, and gives the return value to the callee stub The callee stub sends the value back to the caller stub The caller stub passes that value back to the local procedure 9

10 Stubs Caller = client (initiate, active end) Callee = server (listen, passive end) The stubs are coupled Client stub must know server stub’s IP and port – Sometimes, a port is reserved for RPC Stubs are usually generated by tools – Rpcgen for Sun RPC, wscompile for JAX-RPC, … Other naming: server stub = skeleton 10

11 RPC RPC belongs to the application layer 11 Procedure Interface Definition (in Interface Def Language) Callee Program (in server language) Caller program (in client language) Client Stub (in client language) Server Stub (in server language) generate Network OS call Usual code RPC code call Serialize and sendDeserialize and receive

12 RPC as middleware 12 Application RPC stubs RPC Request-reply protocol, and RPC serialization format OS Middleware layers Middleware: software between OS and application

13 RPC is not P2P In both cases, nodes are clients and servers to each other But in RPC, the goal is to execute a function remotely – A client and a server could use RPC – Peers could use RPC with each other – Peers could simply exchange data, and not use RPC RPC stubs use a client-server paradigm – With a request-response messaging pattern 13

14 SUN RPC: DATE/TIME SERVER EXAMPLE IN C From Unix Network Programming, by Stevens et al. 14

15 Sun RPC AKA Open Network Computing Created in the mid 80s by Sun The developer writes: – interface.x, the interface definition, in Interface Definition Language – callee.c, the server with the remote procedure – caller.c, the client calling the remote procedure The rpcgen compiler generates: – interface.h, to be imported by caller.c and callee.c – callee_stub.c – caller_stub.c 15

16 XDR eXternal Data Representation Created in the mid 80s by Sun Binary encoding The data format exchanged between stubs Serialization format used by: – Network File System (created by Sun) – SpiderMonkey (Firefox JS engine, XDR used to exchange compiled JS) – R (stats tool) 16

17 Sun RPC 17 caller.c interface.x callee_stub.ccaller_stub.c callee.c Import function signature Call network Send XDR Recv XDR Generate interface.h Generate generated Hand-written Import function signature

18 caller.c (I adapted it) server = ‘ ’; client = create_client(server, DATE_PROG, DATE_VERS, "udp"); bin_date = get_binary_date(NULL, client); str_date = bin2str_date(bin_date, client); printf("time on server %s: %s", server, *str_date); 18

19 caller_stub.c (generated and adapted) #include "date.h" static struct timeval TIMEOUT = { 25, 0 }; long * get_binary_date(void *argp, CLIENT *clnt) { static long clnt_res; // return value is a long memset((char *)&clnt_res, 0, sizeof (clnt_res)); // allocate memory cli_call = client_call(clnt, GET_BIN_DATE, // RPC function number (xdrproc_t) xdr_void, // argument type (caddr_t) argp, // argument value (xdrproc_t) xdr_long, // return value type (caddr_t) &clnt_res, // store in this memory area TIMEOUT); if (cli_call != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } 19

20 Sun RPC API client_call create_client And more … 20

21 XML RPC 21

22 XML RPC Over HTTP POST 1998, many language bindings 22

23 XML RPC - request 23 POST /RPC2 HTTP/1.1 User-Agent: Frontier/5.1.2 (WinNT) Host: betty.userland.com Content-Type: text/xml Content-length: 181 examples.getStateName 41

24 XML RPC – success response 24 HTTP/ OK Connection: close Content-Length: 158 Content-Type: text/xml Date: Fri, 17 Jul :55:08 GMT Server: UserLand Frontier/5.1.2-WinNT South Dakota

25 XML RPC – failure response 25 HTTP/ OK Connection: close Content-Length: 426 Content-Type: text/xml Date: Fri, 17 Jul :55:02 GMT Server: UserLand Frontier/5.1.2-WinNT faultCode 4 faultString Too many parameters.

26 XML RPC vs XML: bandwidth  ROOM_ID 1 CODE MR-101 NAME Math Room CAPACITY 30 1 MR-101 Math Room class Room { int id=1; String code="MR-101"; String name="Maths room"; int capacity=30; };

27 REMOTE METHOD INVOCATION 27

28 Proxy objects Equivalent of stub, but for client objects Goal: make RMI transparent to clients – Proxy objects behave like a local object to the invoker – Instead of executing, proxy objects serialize arguments and forward the call + arguments to the remote object Human writes class interface with method names RMI compiler generates proxy classes, skeleton classes, and server dispatcher 28

29 Remote Method Invocation 29 Object A Object B Comm. Module Skeleton for B’s Class Server Process Client Process Proxy Object B Remote Reference Module Dispatcher Remote Reference Module MIDDLEWARE Proxy object is a hollow container of Method names. Remote Reference Module translates between local and remote object references. Dispatcher sends the request to Skeleton Object Skeleton deserializes parameters, sends it to the object, & marshals the results for return

30 More des.pdf des.pdf www2.hh.se/staff/vero/concurrent/lectures/lecture6.pdf Implementing Remote Procedure Calls, Birrell et al https://docs.python.org/2/library/xmlrpclib.html us/library/cc738291%28v=WS.10%29.aspx us/library/cc738291%28v=WS.10%29.aspx ml ml 30


Download ppt "Remote Procedure Call and Remote Method Invocation INF 123 – Software architecture 1."

Similar presentations


Ads by Google