I noticed that a maintainer of gRPC suggested using MAX_CONNECTION_AGE
to load balance long lived gRPC streams in their video, Using gRPC for Long-lived and Streaming RPCs - Eric Anderson, Google. I also found an implemented proposal which only lists C, Java and Go:
Status: Implemented
Implemented in: C, Java, Go
In practice, how do I use MAX_CONNECTION_AGE
in a python server?
You can use grpc.server()
's options
argument:
options – An optional list of key-value pairs (channel_arguments in gRPC runtime) to configure the channel.
You would use GRPC_ARG_MAX_CONNECTION_AGE_MS
, defined in grpc_types.h
:
/** Maximum time that a channel may exist. Int valued, milliseconds.
* INT_MAX means unlimited. */
#define GRPC_ARG_MAX_CONNECTION_AGE_MS "grpc.max_connection_age_ms"
For 30 days as suggested in Using gRPC for Long-lived and Streaming RPCs - Eric Anderson, Google, GRPC_ARG_MAX_CONNECTION_AGE_MS
should be 2592000000
(30*24*60*60*1000
)