2

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();
}
AkshayM
  • 317
  • 6
  • 18

2 Answers2

0

Since gRPC Python and gRPC C++ use the same gRPC Core which does actual job, they should have similar performance in this simple case. Did you check you're building gRPC C++ with release configuration? (debug build is significantly slower)

Esun Kim
  • 189
  • 1
  • Yes gRPC C++ is built with release config. Yes, similar performance is an expectation - but not the outcome - and that is the question itself. – AkshayM Sep 27 '21 at 07:29
0

I know it's an old thread, but I have experienced kinda the same issue.

I had a Python gRPC on server-side, Python and .NET gRPC on client side, and the Python client was much faster. I have used SSL encryption for the gRPC channel. It turned out that SSL was the problem. When I made a channel without encryption, the performance was the same with both clients.

So this issue is highly dependent on what CPU you have I suppose, because some CPUs can do SSL encryption and decryption faster than others. There is also a description about SSL optimization being turned off in some languages in the gRPC repository. In your case, the optimization might caused this experience.

If you didn't used encryption,ignore this. But if someone experience something like this, and used encryption, this might be useful.

kovapatrik
  • 11
  • 2