Performance slowness while hitting gRPC endpoints first time using protobuf-net c#

1.9k Views Asked by At

I have a gRPC server running using the protobuf-net.gRPC using .NET Core 3.1. It uses ASP.NET Core framework and Kestrel behind the scenes to run the HTTP server. I notice that very first time the gRPC endpoints that are hit on this server spend substantially more time in the ASP NET Core middleware compared to subsequent calls on the same endpoint.

Time taken from 
Microsoft.AspNetCore.Routing.EndpointMiddleware[ExecutedEndPoint] : Executing endpoint 'gRPC - /grpc.....'

Until hitting the actual endpoint function in my gRPC server

Time taken for the first time is quite high around 30-40 Ma while the subsequent calls to the same endpoint is around 1-2 ms.

Is this because of the JIT compiler compiling from IL->Native code ? If so, is there an way to get around this first time performance issue other than the obvious means such as forcibly calling the endpoints ?

Regards

1

There are 1 best solutions below

1
On

This could be due to the gRPC design as the channel's connection is not established until the first RPC call is issued.

The 30-40 ms is probably for opening TCP connection + SSL handshake + HTTP/2 settings frames exchange. The following RPC calls reuse this channel/connection and thus don't have this overhead.

For Java there is an experimental API getState that a client can call with a requestConnection = true argument right after channel creation to initiate the connection. Not sure if it's available in C#.