haskell-grpc-native / http2-grpc-haskell

gRPC over HTTP/2 for Haskell, client and server
38 stars 25 forks source link

Add some form of connection manager for the client #29

Open lucasdicioccio opened 4 years ago

lucasdicioccio commented 4 years ago

This feature could be implemented in http2-client as well but for some context: typical usage of gRPC is for microservices within datacenters, where endpoints are replicated. The current design sticks all gRPC calls on a same http2 connection (hence, on a same TCP connection -- and if this connection crashes then the programmers as to restart a client passing all the parameters again). It would be nice to support some sort of connection-managers for balancing all RPCs over multiple http2 sessions (with some programmable control over how to pick a session, how many sessions to open etc.)

greglaun commented 3 years ago

The solution to this is largely specified by the gRPC design. The state machine tracking this information for a channel is specified in https://grpc.github.io/grpc/core/md_doc_connectivity-semantics-and-api.html.

gRPC has a "channel", which is a virtual connection to the an endpoint. An endpoint may be served by many servers. Channels have "subchannels", which are logical connections to a server. The subchannel maintains the actual TCP connection. If a channel dies, there is standard logic to either choose another subchannel, or to repair the connection.

When gRPC does reconnect, it uses an exponential backoff aproach described here: https://grpc.github.io/grpc/core/md_doc_connection-backoff.html.