Seminar 1: Interconnecting individual nodes
Goal: To understand Remote Procedure Calls (RPC) in Python.
Definitions? Remote Procedure Call (RPC) is a protocol that one program can use to request a service from a program located in another computer (or node) on a network without having to understand the network’s details.
- A message based communication scheme should be used to provide remote service as the processes are executing on separate systems.
- The messages exchanged in RPC communication are well structured and are thus no longer just packets of data.
- Each message is addressed to an RPC daemon listening to a port on the remote system, and each contains an identifier of the function to execute and the parameters to pass to that function. The function is then executed as requested, and any output is sent back to the requester in a separate message.
- Using stub function to marshal the argument and send the message to the remote server. Marshalling also indicate the encoding applied over the data sent to the server.
Prerequisites: Python (Python Download) or Python Installation: https://realpython.com/installing-python/ and gRPC
We will get acquainted with RPC procedure by using gRPC inspired by Google in Python. In gRPC, a client application can directly call a method on a server application on a different machine as if it were a local object. The idea is to create a service with specific methods that can be called from a distance. The server uses this service and runs a gRPC server to respond to client requests. On the client side, there is a tool called stub that offers the server method as the server.
N.B By default, gRPC uses Protocol buffers, Google's mature open source mechanism for serializing structured data.
For the first part of this example, we would need gRPC tools to create the client and server stubs.
To install gRPC tools
WORKING PIPELINE FOR gRPC IMPLEMENTATION
- Create a .proto file to define your service
- Generate a gRPC code from the .proto file using a compiler
- Implement the server
- Implement the client
Exercise: Implementing a short gRPC client-server code.(Code)
Implementing server.py
Implementing client.py
This code first sends a request for a message, then sends a message to the server, and finally prints the results of sending the message,
We can continue to run the server and client, and should see the message being sent and reversed as expected.
Task: Define a unique function (e.r Unary, client streaming, server streaming, bidirectional streaming modes) to implement your own simple gRPC client-server communication.
Deliverables: Zip file containing the source code file and the screenshots of the server and the client terminals.
Suggested read or tutorials
- A typical gRPC implementation can be found here.Quick Start
- Basic Tutorials
- Unary gRPC. Unary gRPC
Besides gRPC, other ready available tools and frameworks are available to perform remote procedure calls.
- RPyC in Python
- zeroRPC
- Several ad-hoc solutions in GitHub