My grpc server is in VC++ and transfers 1 giga points (1e9) of data - where each point is 1, 2, 4 or 8 bytes of data depending upon the selected precision. I have 03 clients - one in each language - Cpp-14, Python-3.9 and C# (.net 5.0). C++ uses grpc vc packages, Python uses pip packages and C# uses nuget packages. My PC has 10 Gig ethernet card.
In single threads - the app's max speeds are as Cpp: 4.5 Gbps, C#: 2.5 Gbps, Python: 9 Gbps. Why is python 2x as fast as C++ and almost 4x as fast as C# ?
My code below (main excerpts only):
Proto file:
service data {
rpc get (Request) returns (stream Response) {}
}
message Request {
string source = 1;
uint64 chunksize = 2;
}
message Response {
bytes data = 1;
}
Python code:
def get_data():
index_dict: dict() = {1:'b', 2:'h', 4:'i', 8:'d'}
data = []
request = ABC.Request()
stub = ABC._pb2_grpc.dataStub(self._channel)
response_iterator = stub.get(request)
for response in response_iterator:
data += struct.unpack("2500h", response.data)
return data
C# Code:
using var call = _data.get(request);
var responseStream = call.ResponseStream;
while (await responseStream.MoveNext())
{
var data = responseStream.Current.Data;
ReceivedData.Append(data);
}
C++ Code :
std::unique_ptr<grpc::ClientReader<Response>> reader = stubdata_->get(&context, request);
while (reader->Read(&reply))
{
src += reply.chunk().data_size();
}