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
Request for AsyncLoadBalancer
or a built-in Least Connection Load Balancing Implementation
#236
Comments
Could you tell us more about the use case for async lock? Async lock is only needed if the logic needs to hold the lock across
Reference: https://tokio.rs/tokio/tutorial/shared-state |
Well, Using While using For example, calling
As for atomic methods, it's true we can use persistent data structures to utilize The use case is fairly simple: balancing the load to the least connection upstream. It will be great to have a built-in least connection load balancing implementation. As for other use cases, rather than using |
Note that from https://tokio.rs/tokio/tutorial/shared-state:
In practice we have no problem using sync locks following that guidance. Regarding least connection load balancing, I think that it is possible to use Meanwhile we do acknowledge that the need for a least connection load balancing algorithm to be implemented. |
Using a synchronous mutex from within asynchronous code is fine when talking about deadlocks and where contention remains low. For performance, I would recommend benchmarking under several different senario. And yes, in the cases where the upstreams are static, Hope to have least connection load balancing in pingora soon. I'll close this issue. |
What is the problem your feature solves, or the need it fulfills?
When implementing least connection load balancing, it's necessary to have internal mutability to record connections, which can be achieved using
RwLock
or similar constructs.However, the functions of
BackendSelection
andBackendIter
are defined as non-async
, limiting the implementations to wait for locks without utilizing async runtimes.Describe the solution you'd like
It would be really helpful to have
AsyncLoadBalancer
or a built-in least connection load balancing implementation.Describe alternatives you've considered
To work around this limitation, here are some alternatives:
std::sync::RwLock
.futures::executor::block_on
to wait fortokio::sync::RwLock
in non-async
functions.MyLoadBalancer
according to the currentLoadBalancer
in pingora.The text was updated successfully, but these errors were encountered: