Link Search Menu Expand Document

gRPC Lab

Machines in a distributed system must communicate with one another. One method of doing this is using Remote Procedure Calls (RPCs), which make communication between machines look like ordinary function calls. Effectively, RPCs abstract away the underlying serialization required for raw messaging and allow for an interaction like this:

  • A client calls remoteFileSystem->Read("rutabaga").
  • The underlying RPC library serializes this function call as a request and sends it to the server.
  • The RPC library deserializes the request on the server and runs fileSys->Read("rutabaga"), which returns a response.
  • The RPC library serializes the response, sends it to the client, and deserializes it to give the client the return value for its function call.

Serialization is the process of converting structures into bytes that can be sent via communication protocols like TCP, while deserialization recovers the original structures from the serialized bytes. Serialization formats specify how serialization and deserialization should take place, and allow communicating processes to understand the bytes being received from one another. For example, JSON and YAML are two common serialization formats that often find use in configuration files.

In this lab, you will be familiarizing yourself with gRPC, an open source remote procedure call (RPC) framework that uses Google’s protocol buffer serialization mechanism. You will do so by implementing a very basic key/value (KV) store, which allows clients to put keys in a server-side hash map and read them out later by making requests to the server.

For a brief rundown of how gRPC works, please read this guide. For more specifics on how gRPC works in Rust, you can take a look at this tutorial, but we will be covering the content relevant to the upcoming MapReduce homework in this lab.

Getting started

We recommend doing this lab locally, but you can also do it from your VM. Begin by pulling the starter code:

cd ~/code/personal
git pull staff master
cd lab-grpc

Regardless of whether you are doing the lab locally or on your VM, you will need to install CMake by following the directions here. Make sure you install a relatively new version of CMake (at least 3.20.0) to ensure that you don’t run into any issues. To install CMake on your VM, run the following commands:

      -q -O /tmp/
chmod u+x /tmp/
sudo mkdir /opt/cmake
sudo /tmp/ --skip-license --prefix=/opt/cmake
rm /tmp/
echo "PATH=/opt/cmake/bin:$PATH" >> ~/.cs162.bashrc
source ~/.cs162.bashrc

If Rust is not installed, install it according to the directions here.