Chapter 3 6 Communication in ClientServer Systems CSS














- Slides: 14

Chapter 3. 6: Communication in Client-Server Systems CSS 503 Systems Programming Prof. Munehiro Fukuda Computing & Software Systems University of Washington Bothell CSS 503 Chapter 3. 6: Client Server 0

Remote Procedure Calls n Remote procedure call (RPC) abstracts procedure calls between processes on networked systems n Stubs – client-side proxy for the actual procedure on the server n The client-side stub locates the server and marshalls the parameters n The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server CSS 503 Chapter 3. 6: Client Server 1

RPC/RMI Model Caller (Client) RPC and wait Callee (Server) Request message including arguments Suspended Reply message Including a return value Request message accepted Execution environment created Execution of function body Send reply and wait for the next request Resume execution CSS 503 Chapter 3. 6: Client Server 2

RPC Mechanism Interface Definition Language File Define arguments Register remote functions Client Program Return Call Server Program Return IDL Compiler Server Stub Client Stub (5) Exception? Message (4) Invalid arguments? Decoding Encoding (3) Invalid procedure? Message marshaling Decoding Encoding Retransmission acknowledgments Routing encryption RPC Runtime Receive Send args CSS 503 PRC id client id Call RPC Runtime (Dispatcher) (2) Unauthorized client? Receive Send (1) Intelligible messages? type (call) msg id Chapter 3. 6: Client Server reply fesults type (reply) status failur 3

Client-Server Binding (Sun. RPC) Server Machine Client Machine (2) Locating server Client (3) Server port (xxx) (4) RPC with port xxx (1) register write(), read(), Sendto(), recvfrom() TCP or UDP Portmap Daemon port: xxx Server Transport level or below port: 111 write(), read(), Sendto(), recvfrom() TCP or UDP Network (LAN/WAN) n n n (1) pmap_set(prognum, versnum, protocol, port) (2) and (3) pmap_getport(addr, prognum, versnum, protocol) To check the status of portmap, rpcinfo CSS 503 Chapter 3. 6: Client Server 4

Sun. RPC Modify by yourself example_client. c rpcgen –a example. x example_client. o example_client Client program Your client example_clnt. o example_clnt. c Client stub example_h. c example. x Interface descriptions gcc –c -o Header ld -o example_xdr. c example_xdr. o Marshalling example_svc. o example_svc. c Server program Server stub example_server. o example_server. c Your server CSS 503 example_server Modify by yourself Chapter 3. 6: Client Server 5

Sun RPC (Interface definition) /* * example. x - Speicification of some arithmetic/string service. * Define 2 procedures: * fact( int n ) returns n!. * power( double x, double y ) returns x^^y. * strconc( struct strings ) concatenates src to dest. */ const BUFFER_SIZE = 1024; struct doubles { double a; double b; }; struct strings { char src[BUFFER_SIZE]; char dst[BUFFER_SIZE]; }; program EXAMPLE_PROG { version EXAMPLE_VERS { int FACT( int ) = 1; double POWER( doubles ) = 2; string STRCONC( strings ) = 3; } = 1; } = 0 x 31234567; CSS 503 /* procedure number = 1 */ /* procedure number = 2 */ /* procedure number = 3 */ /* version number = 1 */ /* program number = 0 x 31234567 */ Chapter 3. 6: Client Server 6

Sun RPC (Client) #include "example. h" void example_prog_1(char *host) { CLIENT *clnt; int *result_1; int fact_1_arg; double *result_2; doubles power_1_arg; char * *result_3; strings strconc_1_arg; clnt = clnt_create (host, EXAMPLE_PROG, EXAMPLE_VERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } fact_1_arg = 10; result_1 = fact_1(&fact_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } printf( "fact( 10 ) = %dn", *result_1 ); } int main (int argc, char *argv[]) { char *host; exit (0); } if (argc < 2) { exit (1); host = argv[1]; example_prog_1 (host); power_1_arg. a = 2. 0; power_1_arg. b = 6. 0; result_2 = power_1(&power_1_arg, clnt); if (result_2 == (double *) NULL) { clnt_perror (clnt, "call failed"); } printf( "power( 2. 0, 6. 0 ) = %fn", *result_2 ); strncpy( strconc_1_arg. dst, "xyz ", BUFFER_SIZE ); strncpy( strconc_1_arg. src, "abc ", BUFFER_SIZE ); result_3 = strconc_1(&strconc_1_arg, clnt); if (result_3 == (char **) NULL) { clnt_perror (clnt, "call failed"); } printf( "strconc( "xyz", "abc" ) = %sn", *result_3 ); clnt_destroy (clnt); CSS 503 Chapter 3. 6: Client Server 7

Sun RPC (Server) #include "example. h" #include <math. h> #include <string. h> int * fact_1_svc(int *argp, struct svc_req *rqstp) { static int result; int i; result = 1; for ( i = *argp; i > 0; i-- ) result *= i; } return &result; double * power_1_svc(doubles *argp, struct svc_req *rqstp) { static double result; result = pow( argp->a, argp->b ); } return &result; char ** strconc_1_svc(strings *argp, struct svc_req *rqstp) { static char * result; result = strcat( argp->dst, argp->src ); } CSS 503 return &result; Chapter 3. 6: Client Server 8

Types of Distributed OS n Network Operating Systems n Distributed Operating Systems CSS 503 Chapter 3. 6: Client Server 9

Network-Operating Systems n Users are aware of multiplicity of machines. Access to resources of various machines is done explicitly by: n n n Remote logging into the appropriate remote machine (telnet, ssh) Remote Desktop (Microsoft Windows) Transferring data from remote machines to local machines, via the File Transfer Protocol (FTP) mechanism CSS 503 Chapter 3. 6: Client Server 10

Distributed-Operating Systems n Users not aware of multiplicity of machines n Access to remote resources similar to access to local resources n SSI: single system image n Data Migration – transfer data by transferring entire file, or transferring only those portions of the file necessary for the immediate task n Computation Migration – transfer the computation, rather than the data, across the system CSS 503 Chapter 3. 6: Client Server 11

Distributed-Operating Systems (Cont. ) n Process Migration – execute an entire process, or parts of it, at different sites n Load balancing – distribute processes across network to even the workload n Computation speedup – subprocesses can run concurrently on different sites n Hardware preference – process execution may require specialized processor n Software preference – required software may be available at only a particular site n Data access – run process remotely, rather than transfer all data locally CSS 503 Chapter 3. 6: Client Server 12

Discussion n Solve textbook Ex 3. 12: Consider the RPC mechanism. Describe the undesirable consequences that could arise from not enforcing either the “at most once” or “exactly once” semantic. Describe possible uses for a mechanism that has neither of these guarantees, (e. g. , how about at least once? ). n The following features are all categorized in distributed operating systems. What resources are network-unaware and/or moving among computing nodes? n n n RPC and RMI Language environment: MPI and Map. Reduce DSM including Java. Space NFS and AFS Job schedulers: Open. PBS Solve textbook Ex 16. 7: why is process migration impossible in different computer architecture and OS? CSS 503 Chapter 3. 6: Client Server 13