New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing async functions for loadbalancer/picker #1771
Comments
I responded to the Gitter message but I got no response so I'll say the same thing here: First I want to clarify that For leaf load balancers (pick first and round robin), those events are generally subchannel state changes. I suggest also looking at the CDS and EDS load balancers in the grpc-js-xds package. Those both make remote requests and use the asynchronous responses to construct child load balancers, which eventually provide state updates. |
Hi. I did not notified Gitter message, sorry. For For |
The picker API was designed for a load balancing implementation in which the list of endpoints may be determined using an asynchronous operation, but the client can synchronously determine which of those resulting subchannels to use. It simply does not support performing an additional asynchronous operation for every request to determine which subchannel to use. That pattern adds a lot of per-request overhead, which we want to minimize. |
Understand, and that's what I was worry about. However the whole load balancer is not so easy to implement in picker's style, and the per-request async operation seems necessary. Do you suggest any other way to implement this? |
Can you share more details about how your load balancing implementation works, and why you need to perform the last step of load balancing asynchronously at the time the request is made? |
The load balancing framework is kinda complex. It's not designed for gRPC, so it has several components which:
So basically, this framework itself is similar to gRPC's own subchannel management mechanism. |
Problem
I'm writing a customized loadbalancer and picker (implementing
grpc.experimental.Picker
andgrpc.experimental.LoadBalancer
). In my implementation, the loadbalancer is meant to get load status from a remote endpoint, and picker would always check the remote endpoint to see if the subchannel is in "disabled" state.For example, in
Picker.pick
, to get information from my remote endpoint, I need to call the function like this:Currently,
LoadBalancer.updateAddressList
andPicker.pick
are all sync functions, and not accepting aPromise<>
. Also, the return value can not be set via a callback. This makes it impossible to call the remote endpoint in those two functions.However, the same way of checking information from remote endpoint works well for the Golang and C++ version since in those languages
Promise
works in a different way.Possible solution
Add
async
toLoadBalancer.updateAddressList
andPicker.pick
like this:Or add
pickAsync
as an alternative.I had thought if callback is acceptable, but I think it would make no differences than using
await
.Possible Problems
It might not be a wise idea to make
Pick
andLoadbalancer
costing too much time, considering they are frequently called. However, allowingPromise
here does not mean users have to call remote (they can still write a simple picker and choose subchannel without external information`. Additionally, considering customizing those two objects are in experimental state and if you are writing code for them, you should have considerable knowledge of how gRPC call works, users should make their own responsibility if they take the risk to call remote endpoint for additional information for picking.The text was updated successfully, but these errors were encountered: