Skip to content

BackendSelection improvements for least connections#269

Closed
Object905 wants to merge 3 commits into
cloudflare:mainfrom
Object905:main
Closed

BackendSelection improvements for least connections#269
Object905 wants to merge 3 commits into
cloudflare:mainfrom
Object905:main

Conversation

@Object905
Copy link
Copy Markdown

@Object905 Object905 commented Jun 8, 2024

Hi. I wanted to implement my own backend selection (basically least connections), but faced some inconvenience and issues.

To address Inconvenience:
Moved BackendIter bound into BackendSelection::Iter.
It was only used with this bound everywhere anyway, even docs says that Iter should be BackendIter.
Can't see any reason why it's like that. Tested against rust 1.72 to verify that it satisfies msrv.
It doesn't break any existing code, just makes bound S::Iter: BackendIter redundant.

Issues:

  1. selector field in LoadBalancer is private, but I needed to access it to share some handle that will be used to notify selector of pending upstream requests.
    It's possible to achieve this by other means (either global state, but then it's hard to share code, or more api churn and changing public interfaces, which I don't want to do here).

  2. When backends are updated new instance of BackendSelection is created and replaced, but to keep handle from previous selector I had to resort to global state. So I added previous: Option<Arc<Self>> argument that will be passed in LoadBalancer::update, so it's possible to keep provided handle or some other state. This is somewhat breaking change.

Related Issue: #144
Maybe later after my experiments will make a PR for least connections.

@Object905
Copy link
Copy Markdown
Author

Object905 commented Sep 21, 2024

Closing, since Backend can now have Extensions, that can have needed shared state for least connections to be implemented.

BackendIter bound still seems to me not ideal, but should have made it a separate PR from the start I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant