golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.36k stars 17.38k forks source link

net: DNS load balancing during bursts of traffic #31698

Open shamwow opened 5 years ago

shamwow commented 5 years ago

Right now inflight DNS lookups are grouped together.

Since DNS resolution picks the first available IP, this has the side effect of resolving the same IP when there are bursts in traffic.

This was surprising to me since I expected load to be distributed amongst the resolved hosts, especially during these bursts (assuming equal RFC 6724 weighting).

Load distribution via DNS seems like a common use case/expectation - it would be nice to be able to enable randomized DNS resolution. Being able to disable DNS query grouping or customize the way the group key is generated would also work.

ianlancetaylor commented 5 years ago

It does not make sense to me to start doing a separate DNS query for each connection. But perhaps if the DNS query returns multiple addresses, we could arrange for each member of the singleflight group to get a randomly chosen address.

shamwow commented 5 years ago

Randomizing each member of a singleflight group seems like it will require some amount of refactoring. For one, whether or not a request was in a group is entirely encapsulated by singleflight. Also, at the point singleflight is used, the addresses are already sorted by RFC6724.

So the grouping/randomization should be done before we apply the RFC6724 sorting rules[1] and there needs to be a way to know whether a request was grouped by singleflight.

[1] Another option is to randomize the resolved addresses and sort again by RFC6724 instead of moving where singleflight is called