akka / akka-grpc

Akka gRPC
https://doc.akka.io/docs/akka-grpc/
Other
432 stars 123 forks source link

setting maxConnectionAge on server #967

Open pawelwan opened 4 years ago

pawelwan commented 4 years ago

Hi, in netty-based grpc-java it is possible to define the parameter maxConnectionAge on the server like this:

NettyServerBuilder.forPort(...)
    .addService(...)
    .maxConnectionAge(maxConnectionAge, TimeUnit.MILLISECONDS)
    .build()

Is it possible to get the same functionality with akka-grpc? It's needed to perform client-side load balancing as shown here: https://github.com/jtattermusch/grpc-loadbalancing-kubernetes-examples#example-1-round-robin-loadbalancing-with-grpcs-built-in-loadbalancing-policy (setting GRPC_MAX_CONNECTION_AGE on server)

raboof commented 4 years ago

Hmm, I'm not aware of a way to do this.

You could perhaps achieve this from the client side via the withChannelBuilderOverrides escape hatch (https://github.com/akka/akka-grpc/blob/1c7e655ac9a495468cfdfe486f9270db0aac9515/runtime/src/main/scala/akka/grpc/GrpcClientSettings.scala#L236)?

pawelwan commented 4 years ago

Thanks for the quick answer. Did you mean any particular option available in NettyChannelBuilder? I was browsing through the options available there, but I don't see one that will allow me to achieve the same behavior as maxConnectionAge on the server-side.

raboof commented 4 years ago

Ah, sorry - I assumed such an option would be available, but I guess I was wrong...

thyandrecardoso commented 4 years ago

I was also looking for something like that.

GRPC_MAX_CONNECTION_AGE forces clients to reconnect, thus giving them the opportunity to reach a different backend. This is also done transparently for the application code (https://github.com/grpc/proposal/blob/master/A9-server-side-conn-mgt.md; https://github.com/grpc/proposal/blob/master/A6-client-retries.md#transparent-retries).

For example, with kubernetes cluster ip services this is a very easy way to have some kind of load balancing.

Is there any way to replicate this behavior with the current akka-grpc API, or any plans to provide such a feature?

raboof commented 4 years ago

For example, with kubernetes cluster ip services this is a very easy way to have some kind of load balancing.

Is there any way to replicate this behavior with the current akka-grpc API

I think the most common way to approach this currently is to use DNS to discover the individual IP's of the target services, and use the 'round-robin' loadbalancing to balance the load over them.

any plans to provide such a feature

I don't think there is anyone planning on working on this right now.

On the client side, currently we're building on top of the grpc-java client, so anything that is possible there should be possible to expose in Akka gRPC.

In the longer term we might want to allow building the client based on Akka HTTP instead, but Akka HTTP does not yet have HTTP/2 support at the client side. Contributions there are definitely welcome, see https://github.com/akka/akka-http/issues/3226 .

I think it would be great if (either based on grpc-java or akka-http) it would be possible to:

  1. integrate the discovery and the load balancing so that when new nodes are discovered, new connections are made accordingly.
  2. allow configuring load balancing so an appropriate number of connections is made to a cluster ip service.

On the server side we are already based on Akka HTTP, so possibly we could add something like (GRPC_)MAX_CONNECTION_AGE there - though it feels like solving this at the server side might be less elegant than doing it at the client side.