grpc-go icon indicating copy to clipboard operation
grpc-go copied to clipboard

ringhash: spread out endpoints in the ring

Open easwars opened this issue 3 years ago • 0 comments

Currently, when creating the ring, we assign the same hash to all entries corresponding to one address. This means that the ring will have addresses in a contiguous fashion. https://github.com/grpc/grpc-go/blob/28de4866ce7440b675662abbdd5c43b476bd4dae/xds/internal/balancer/ringhash/ring.go#L98

Spreading out instances of the same address in the ring seems better, because when subchannels are unreachable, the picker goes through the ring in order, so it's better to not have the same address many times in a row. This is what c-core does, and we should as well.

easwars avatar Jun 21 '22 23:06 easwars

Actually, looks like we are already spreading the instances of the same address across the ring.

for float64(idx) < targetIdx {
	h := xxhash.Sum64String(scw.sc.addr + strconv.Itoa(len(items)))
	items = append(items, &ringEntry{idx: idx, hash: h, sc: scw.sc})
	idx++
}

items is pre-allocated with capacity. But len(items) keeps changing with each iteration of the above loop as we append more entries to the slice.

So, nothing needs to be done here.

easwars avatar Aug 29 '22 23:08 easwars