Remote Procedure Calls CS587x Lecture Department of Computer Science Iowa State University.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

CSE 486/586 Distributed Systems Remote Procedure Call
Remote Procedure Call (RPC)
Remote Procedure Call Design issues Implementation RPC programming
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY.
Tam Vu Remote Procedure Call CISC 879 – Spring 03 Tam Vu March 06, 03.
Remote Procedure CallCS-4513, D-Term Remote Procedure Call CS-4513 Distributed Computing Systems (Slides include materials from Operating System.
Implementing Remote Procedure Calls Andrew Birrell and Bruce Nelson Presented by Kai Cong.
INF 123 SW ARCH, DIST SYS & INTEROP LECTURE 9 Prof. Crista Lopes.
CS6223: Distributed Systems Remote Procedure Call (RPC)
Distributed Systems Lecture #3: Remote Communication.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
CSE331: Introduction to Networks and Security Lecture 11 Fall 2002.
Remote Procedure Call Chin-Chih Chang. Remote Procedure Call Remote Procedure Call (RPC) is a protocol that allows programs to call procedures located.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
Outcomes What is RPC? The difference between conventional procedure call and RPC? Understand the function of client and server stubs How many steps could.
Communication in Distributed Systems –Part 2
Client-Server Communication Sockets Remote Procedure Calls Remote Method Invocation (Java)
.NET Mobile Application Development Remote Procedure Call.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
Remote Procedure CallCS-502 Fall Remote Procedure Call CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System Concepts,
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W
CSE 486/586 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
Remote Procedure Call Andrew Whitaker CSE451. Remote Procedure Call RPC exposes a programming interface across machines: interface PriceService { Price.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
CS425 /CSE424/ECE428 – Distributed Systems – Fall Nikita Borisov - UIUC1 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S.
11 September 2008CIS 340 # 1 Topics To examine the variety of approaches to handle the middle- interaction (continued) 1.RPC-based systems 2.TP monitors.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
 Remote Procedure Call (RPC) is a high-level model for client-sever communication.  It provides the programmers with a familiar mechanism for building.
CSE 451: Operating Systems Winter 2015 Module 22 Remote Procedure Call (RPC) Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
Page 1 Remote Procedure Calls Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Chapter 5: Distributed objects and remote invocation Introduction Remote procedure call Events and notifications.
Remote Procedure CallCS-502 Fall Remote Procedure Call (continued) CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
Remote Procedure Call Andy Wang Operating Systems COP 4610 / CGS 5765.
Remote Procedure Call RPC
Mark Stanovich Operating Systems COP Primitives to Build Distributed Applications send and receive Used to synchronize cooperating processes running.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Computer Science Lecture 3, page 1 CS677: Distributed OS Last Class: Communication in Distributed Systems Structured or unstructured? Addressing? Blocking/non-blocking?
Remote Procedure Call (Introduction)
Distributed objects and remote invocation Pages
Distributed Systems Lecture 8 RPC and marshalling 1.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Topic 3: Remote Invocation Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
Prof. Leonardo Mostarda University of Camerino
CSE 486/586 Distributed Systems Remote Procedure Call
CSE 451: Operating Systems Winter 2006 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Sarah Diesburg Operating Systems COP 4610
CSE 451: Operating Systems Autumn 2003 Lecture 16 RPC
CSE 451: Operating Systems Winter 2007 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
CSE 451: Operating Systems Winter 2004 Module 19 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Spring 2012 Module 22 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Autumn 2009 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
EECE.4810/EECE.5730 Operating Systems
CS-502, Operating Systems Fall 2009 (EMC)
Remote invocation (call)
CSE 451: Operating Systems Autumn 2010 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Middleware and ORB CS 314 Operating Systems
Lecture 7: RPC (exercises/questions)
CSE 451: Operating Systems Winter 2003 Lecture 16 RPC
Middleware and ORB CS 314 Operating Systems
CSE 451: Operating Systems Messaging and Remote Procedure Call (RPC)
Presentation transcript:

Remote Procedure Calls CS587x Lecture Department of Computer Science Iowa State University

Java-to-C (J2C) RPC Java Application C RPC Implementation GetLocalTime(time, valid) GetLocalOS(OS, valid) Call an RPC Send/Recv() TCP/UDP Socket Send/Recv() Call the RPC implementation

Interface: How to Make an RPC? C Interface How to call its C implementation? Java Interface How to represent a C function in Java How to set inputs How to execute How to get outputs

Example: GetLocalTime() typedef struct { int *time; char *valid; } GET_LOCAL_TIME; void GetLocalTime(GET_LOCAL_TIME *ds);

C Interface Design Call standard function implementation e.g., GetLocalTime(char *buffer)

Java Interface Design Each RPC is associated with a class class GetLocaltime(); Steps of making an RPC call 1. Instantiate an RPC object obj = new GetLocalTime(); 2. Set inputs obj.valid.setValue(FALSE); 3. Execute obj.execute(IP, PORT); 4. Get outputs int t = obj.time.getValue();

RPC Class of GetLocalTime() class GetLocalTime { c_int time; c_char valid; public int execute(string IP, int port); } class c_int { byte[] buf = byte[4]; public int getSize(); public int getValue(); public void setValue(byte[] buf); public void setValue(int v); public byte[] toByte(); }

Implementation of execute() Communication protocol CmdIDCmdBufLength JavaC Make RPC Call Return RPC result Length (4 bytes): the length of CmdID+CmdBuf CmdID (100 bytes): the command ID CmdBuf (dynamic): the parameters to the command

Implementation of Execute() Create a binary buffer 1. int length = 100+time.getsize()+valid.getsize(); 2. byte[] buf = new byte[4+length]; Marshall parameters into the buffer 1. buf[0, 4] = length; offset = 4; 2. buf[offset, 100] = “GetLocalTime”; offset^^ 3. buf[offset, time.getSize()] = time.toByte(); offset^^ 4. buf[offset, valid.getSize()] = valid.toByte(); Send/receive the buffer to/from the RPC server 1. s = CreateSocket(IP, port); 2. SendPacket(s, buf, buf.length()); 3. RecvPacket(s, buf, buf.length()); Set parameters according to the buffer 1. time.setValue(buf, 100); 2. valid.setValue(buf, 100+time.getSize());

C Implementation Receive a command 1. s = CreateSocket(port); 2. length = new byte[4]; 3. RecvPacket(length, 4); 4. buf = new byte[length]; 5. RecvPacket(s, buf, length); Execute the command 1. switch buf[0-99] of 2.case “GetLocalTime”: 3.{ 4.ds = malloc(sizeof(GET_LOCAL_TIME)); 5.ds.time=&buf[100]; 6.ds.valid = &buf[100, sizeof(time field)]; 7.GetLocalTime(&ds); 8.free(ds); 9.break ; 6.} Send the command back 1. SendPacket(s, buf, length);

Problems of Hard Implementation A new command needs to be added? An existing command needs to be deleted? Some parameters to a command need to be changed? Add a new field Delete an existing field Change the type of an existing field

A General Implementation Supported data types Generic marshalling/unmarshalling J2C compiler Given a C function, automatically generates its corresponding Java class Make RPC communication transparent

RPC Class of GetLocalTime() class GetLocalTime { c_int time; c_char valid; public int execute(string IP, int port); } class c_int { byte[] buf = byte[4]; public int getSize(); public int getValue(); public void setValue(byte[] buf); public void setValue(int v); public byte[] toByte(); }

Implementation of Execute() Create a binary buffer 1. int length = 100+time.getsize()+valid.getsize(); 2. byte[] buf = new byte[4+length]; Marshall parameters into the buffer 1. buf[0, 4] = length; offset = 4; 2. buf[offset, 100] = “GetLocalTime”; offset^^ 3. buf[offset, time.getSize()] = time.toByte(); offset^^ 4. buf[offset, valid.getSize()] = valid.toByte(); Send/receive the buffer to/from the RPC server 1. s = CreateSocket(IP, port); 2. SendPacket(s, buf, buf.length()); 3. RecvPacket(s, buf, buf.length()); Set parameters according to the buffer 1. time.setValue(buf, 100); 2. valid.setValue(buf, 100+time.getSize());

C Implementation Receive a command 1. s = CreateSocket(port); 2. length = new byte[4]; 3. RecvPacket(length, 4); 4. buf = new byte[length]; 5. RecvPacket(s, buf, length); Execute the command 1. switch buf[0-99] of 2.case “GetLocalTime”: 3.{ 4.ds = malloc(sizeof(GET_LOCAL_TIME)); 5.ds.time=&buf[100]; 6.ds.valid = &buf[100, sizeof(time field)]; 7.GetLocalTime(&ds); 8.free(ds); 9.break ; 6.} Send the command back 1. SendPacket(s, buf, length);

Can a Tool Does This? Given an RPC definition (i.e., a C data structure), the tool should generate the corresponding RPC class make the communication of RPC transparent to users, i.e., when call Execute(),  marshal the parameters  send/recv command to/from the RPC server  set the parameters accordingly

Challenge – Given an RPC definition, can we make a tool to generate the red codes accordingly?

Keys to the Solution Define a generic RPC model generic data structure and field RPC Implementation replies only on the generic model Parameter marshalling Execution Parameter unmarshalling Based on an RPC definition, we need to generate only its corresponding RPC class

What Defines a Data Structure typedef struct { int *time; char *valid; } GET_LOCAL_TIME; struct = name + a list of fields What can be changed? Name of data structure (i.e., RPC) Number of fields Each field  Data type  Variable name

What Defines a Field Field = type + name Primitive data type int (4 bytes) short (2 bytes) char (1 bytes) etc. Complex data type data structure array typedef struct { int x; char y; short z[20]; } DS1; typedef struct { DS1 x1[100]; DS2 *x2; } DS2;

Data Structure Abstraction public abstract class BaseStruct { String Name; BaseField Field[] = null; public byte[] toByte() { for (int i=0; i<Field.length; i++) { buf = buf + Field[i].toByte(); } public void setValue(byte[] buf} {…} public int getSize(){…}; }

Field Abstraction public abstract class BaseField { String Name; BaseType BType = null; BaseType BTypeArray[] = null; BaseStruct BStruct = null; BaseStruct BStructArray[] = null; public BaseField(String name, BaseType bt) { Name = name; Btype = bt } public BaseField(String name, BaseType bta[]){…} public BaseField(String name, BaseStruct bs){…} public BaseField(String name, BaseStruct bsa[]){…} public byte[] toByte(); public byte[] setvalue(byte buf[]); public int getSize(); }

Primitive Type Abstraction public abstract class BaseType { byte buffer[]; int myType; public byte[] toByte(); public byte[] setvalue(byte buf[]); public getSize(); } public class U8 extends BaseType { public U8(char value) { buffer = new byte[1]; buffer[0] = value; myType = TYPE_U8; }

Primitive Array Abstraction public class BaseArray extends BaseType { int ArrayType; public BaseArray(int type, int array_size); public int getSize(); } public class U8_ARRAY extends BaseArray { public U8_ARRAY(int size) { super(TYPE_U8_ARRAY, size); }

Java Application C RPC Implementation GetLocalTime(time, valid) GetLocalOS(OS, valid) BaseStruct Send/Recv() TCP/UDP Socket Send/Recv() Call the RPC implementation GetLocalTimeGetLocalOS ::: RPC_n

Implementation of DS.Execute() Create a binary buffer int length = 100; for (int i=0; i<ds.getFieldNumber(); i++) { length = length + ds.field[i].getsize(); } byte[] buf = new byte[4+length]; Marshall parameters into the buffer buf[0, 4] = length; offset = 4; buf[offset, 100] = ds.getName(); offset = offset + 100; for (int i=0; i<ds.getFieldNumber(); i++) { buf[offset, ds.filed[i].getSize()] = ds.field[i].toByte(); offset = offset + ds.filed[i].getSize(); } Send/receive the buffer to/from the RPC server s = CreateSocket(IP, port); SendPacket(s, buf, buf.length()); RecvPacket(s, buf, buf.length()); Set parameters according to the buffer offset = 100; for (int i=0; i<ds.getFieldNumber(); i++) { Ds.field[i].setValue(buf, offset); offset = offset + ds.field[i].getSize(); }

Equavalent RPC Class typedef struct { int x; char y; short z[20]; } DS1; typedef struct { DS1 x1[100]; DS2 *x2; } DS2; public class DS1 { S32 x = new S32(); U8 y = new U8(); S16 z[] = new S16[20]; } public class DS2 { DS1 x1[] = new DS1[100]; DS2 x2 = new DS2(); } DS2;

Testing J2C Java Application C RPC Implementation GetLocalTime(time, valid) GetLocalOS(OS, valid) Call an RPC Send/Recv() TCP/UDP Socket Send/Recv() Call the RPC implementation

Remote Procedure Call What is RPC for? Allowing programs to call procedures located on other machine transparently Send/Receive do not conceal communication Scope of use Distributed computing  Task and data partitioned environments  Task distribution Front-end load-balances across functional back ends Services  Client-server model  Mail servers, databases (transaction servers)

Ordinary Function Call user space calling program called function thread of execution ord_funct(); ord_funct(void); { }

Remote Procedure Call rem_funct(); rem_funct(void); { } user space client program local host user space server program remote host thread of execution RPC call -- return blocked thread

RPC Goals Client program only sees an ordinary function call to the client stub Server functions are ordinary functions The underlying mechanism for transporting requests and returning them should be transparent to the programmer RPC should be independent of the transport protocol

How RPC Works?

Client Stub Responsible for Converting arguments and assembling them into a message for network transmission Sending the message to the specified remote machine and receiving the response back Passing the response to the caller

Marshaling Conversion to a network message is called marshaling the arguments Converts to machine independent format so machines with different architectures can participate (e.g., XDR - external data representation) Then the client stub makes a system call to the kernel of the OS (e.g., using TCP/UDP sockets) to send the message over the network and the client stub waits for a reply

Server Stub When a client request arrives, the server kernel passes it to the waiting server stub The server stub unmarshals the arguments and calls the requested service as a local function call When the function call returns, the server stub marshals the return values into an appropriate network message and performs a system call (e.g., using TCP/UDP sockets) to transmit the message to the client

RPC Programming Steps Define remote APIs using IDL (Interface Definition Language) Specify function parameters (i.e., types) Run IDL compiler to generate server and client stubs Implement the remote APIs Compile the entire set of programs your own code the stub files generated by IDL compiler

Implementation Issues How to marshal/unmarshal messages? Data type conversion Big/little-endian conversion Parameter passing  Reference/value (c)  Object serialization (java)

What we have covered Concept of RPC An implementation example Java_to_C (J2C) RPC

Java-to-C (J2C) RPC A hard implementation Not flexible Hard to maintain/upgrade A general implementation of J2C Supported data types Generic marshalling/unmarshalling J2C compiler  Given a C function, automatically generates its corresponding Java class  Make RPC communication transparent