How to reduce the number of gRPC packets

Viewed 36

Sniffing the packets transmitted for a simple echo service Python gRPC example shows that there's 17 packets transmitted for a single message exchange (including SYNs) if the channel is new and 6-8 packets when a channel is reused.

Here's the example protofile:

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

And here's the Python code to run it:

import grpc
import helloworld_pb2
import helloworld_pb2_grpc

channel = grpc.insecure_channel('localhost:50051')
stub = helloworld_pb2_grpc.GreeterStub(channel)

# Try with a brand new channel first
print(stub.SayHello(helloworld_pb2.HelloRequest(name='you')))  # 17 packets

# Let's reuse the channel this time
print(stub.SayHello(helloworld_pb2.HelloRequest(name='you')))  # 6-8 packets; still too much :-(

A Wireshark capture shows that all the packets be between 66 and 176 bytes long, so there's obviously no need to transmit a huge amount of data in total. They could well fit into 1 for each request and response (totalling to 2 packets), but for some reason I'm consistently seeing them fragmented like this (note: testing on loopback, Linux 5.4).

Is there any way to reduce the number of packets?

0 Answers
Related