The goal of this repository is to get familiar with google's take on RPC calls. I'll be running a python client with a C++ server. The simple idea will be to run a function remotely that will do a nested for loop for N iterations and returns the time taken. Obviously C++ will be a lot faster than python (this was not actually the case). I'll compare and contrast the time taken between the gRPC call and the call in python.
Steps to reproduce:
Prerequisites - make sure that protoc and grpc are installed on your system.
Then you can run the setup.sh script to create and activate the venv with
- Run
./setup.shand then activate venv viasource venv/bin/activate- this will set up the venv with requirements, compile the loop.proto file using protoc, and then compile the C++ server
- Start the C++ server using
./server - Run the python client via
python python_files/client.pyto see the speed difference
Example output:
(venv) fss@n007h130 GRPC-practice % python python_files/client.py
Time taken by gRPC C++ server: 1843.00 microseconds
Time taken by Python server: 6176.95 microseconds
Interestingly we see that the difference is not so large (unlike what those LinkedIn posts with balls moving horizontally would lead you to believe). Apparently this is because in the code, we are just simluating work by doing nothing. This is pretty optimized on python too, hence the relatively small speed difference of only a factor of 3 in favor of C++.