Skip to content
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

net/http: Client round-robin across persistent connections #34511

Open
CAFxX opened this issue Sep 25, 2019 · 3 comments
Open

net/http: Client round-robin across persistent connections #34511

CAFxX opened this issue Sep 25, 2019 · 3 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@CAFxX
Copy link
Contributor

CAFxX commented Sep 25, 2019

When connecting directly to a service spread across multiple hosts with DNS "load-balancing" it would be ideal if http.Client could round-robin requests over persistent connections to the multiple hosts listed in the A record.

Right now, if you want to ensure that load is balanced the only practical option is to disable HTTP keepalives.

One way this could be done is to have idle connection pools for each different A record, and do a DNS resolution for every request to decide which pool to use for that request.

This round-robin mode should likely be opt-in (or opt-out). When enabled, given a DNS record like the following:

example.local   60   IN   A   10.0.0.1
example.local   60   IN   A   10.0.0.2

http.Client would send roughly half the requests to .1 and half to .2, even when using persistent connections, and even if the client only ever sends requests serially.


Until this is fixed, if someone else also needs this you can take a look at https://github.com/CAFxX/balancer.

@agnivade agnivade changed the title http.Client round-robin across persistent connections net/http: Client round-robin across persistent connections Sep 25, 2019
@agnivade
Copy link
Contributor

@bradfitz @fraenkel

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 25, 2019
@agnivade agnivade added this to the Unplanned milestone Sep 25, 2019
@bradfitz
Copy link
Contributor

Agreed. I've been thinking about things like this as part of #23707 and making the connection pool interface more explicit/configurable. Currently it's a pretty hidden detail.

@frittentheke
Copy link

@bradfitz could you kindly give an update if you are working on load-balancing / round-robing requests at all? #23707 seems dead.

@CAFxX I know you did implement https://github.com/CAFxX/balancer, but do you have any plans to get (something like) this into upstream net/http then? Would be great to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants