Aaron Hudon
Aaron Hudon

Reputation: 5839

gRPC - request response performance

gRPC 1.1.0 C# .NET 4.6 Windows 7 / Windows 10

I have just tested out the performance of gRPC in C# and am puzzled about its performance between computers. Small messages take a consistent 200ms send/reply time, and larger messages (around 1500 characters) are sub-millisecond. See client/server code below. Is there additional configuration needed to handle small messages?

My test is following the getting started guide here: http://www.grpc.io/docs/quickstart/csharp.html

In a nutshell, there is a Greeter service with a SayHello endpoint accepting HelloRequest and responds with a HelloResponse.

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

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

Client

Again, nearly the same as the sample. Notice the stringLength variable. When it is set to a value between 1-1200(ish), the time to receive a response is consistently 200ms

class Program
{
    static void Main(string[] args)
    {
        var channel = new Channel("192.168.82.254", 50051, ChannelCredentials.Insecure);

        var client = new Greeter.GreeterClient(channel);
        var stringLength = 1500;
        for (var x = 0; x < 50; x++)
        {
            var sw = Stopwatch.StartNew();
            var req = new HelloRequest { Name = new String('x', stringLength) };
            var reply = client.SayHello(req);
            sw.Stop();
            Console.WriteLine($"Greeting: {sw.ElapsedMilliseconds} ms");
        }           
        Console.ReadLine();
    }   
}

Server

Pretty simple, handles the request and responds back. Verbatim from the sample.

const int Port = 50051;

static void Main(string[] args)
{
    Server server = new Server
    {
        Services = { Greeter.BindService(new GreeterImpl()) },
        Ports = { new ServerPort("192.168.82.254", Port, ServerCredentials.Insecure) }
    };
    server.Start();

    Console.WriteLine("Greeter server listening on port " + Port);
    Console.WriteLine("Press any key to stop the server...");
    Console.ReadKey();

    server.ShutdownAsync().Wait();
}

class GreeterImpl : Greeter.GreeterBase
{
    // Server side handler of the SayHello RPC
    public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
    {
        return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
    }
}

Upvotes: 2

Views: 3222

Answers (1)

Jan Tattermusch
Jan Tattermusch

Reputation: 1663

The 1.1.x dashboard seems to indicate that version 1.1.0 still has a problem with ping-pong timing on Windows - https://github.com/grpc/grpc/issues/8806. That seems to be fixed on current master and in v1.2.x. Please use the 1.2.0-pre1 nugets to verify (we're really close to 1.2.0 release now, so the official 1.2.0 packages will follow pretty soon - in the meantime, having a confirmation from you would be very useful).

The master dashboard

Upvotes: 2

Related Questions