Skip to content

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

@CAFxX

Description

@CAFxX

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions