gocql
gocql copied to clipboard
Optimise `tokenAwareHostPolicy.Pick`
Create in continuation of discussion from https://github.com/scylladb/gocql/issues/480
When we design logic for it we should consider the following:
- Performance should be optimized for most-common case, which is cluster is healthy and not overloaded
- When cluster is either overloaded or one or more nodes down, we should ensure fair distribution of execution attempts on all active nodes.
Honoring first point, we should not unnecessary allocate up until first node is pulled from the execution plan (NextHost call), and avoid congestion that can come with mutexes or atomics where it possible.
On next NextHost call, performance it not that critical anymore, since it is assumed that cluster is either overloaded or not healthy, which is not common case.
Implementation
Quick description of how it should look like:
- Pick a random UUID from the tablet replicas, remember it, find the corresponding node, and return it.
- If the driver needs another node, take a copy of the replica set, exclude the already-picked UUID, pick another at random, and return the corresponding node.
- Repeat as needed: each time, reduce the set by the UUIDs already used.