Why you need to reuse a gRPC channel
When you connect the gRPC client to the server, you do so via a configurable channel. When the channel is opened, the following things happen:
- A socket is opened
- The TCP connection is established
- Transport Layer Security (TLS) is negotiated and applied
- An HTTP/2 connection is started
Once these steps have been completed, gRPC calls can be made to the server.
Because opening a channel requires all these steps to take place, which represent multiple roundtrips to the server, it's better to reuse the channel while you can. If you already have an existing channel open, you can start making gRPC calls on it right away. However, if you recreate the channel every time you make a call, you will need to perform all these steps every single time. If you need to make many calls, this may slow down your system substantially.
In C#, the gRPC channel is represented by the GrpcChannel
class from the Grpc.Net.Client
namespace...