Add optional round-robin channel selection for affinity binding calls. #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently a binding call (as any other call without an affinity key) gets the least busy channel, i.e. channel that has fewest active streams. The current logic may not suit all the cases for binding new affinity keys in an optimal way.
It works well when the upstream issues bind calls infrequently and uses the affinity keys from these calls immediately. This way the channels used for the bind calls get utilized by the time a next bind call is issued and affinity keys remain balanced across channels.
But if the upstream makes several bind calls one after another and does not use the returned affinity keys right away, then the affinity keys will not be balanced.
For example:
Let's assume we have this situation: we have 3 long running calls on channel 1 and 3 each and 1 call on the channel 2:
New bind call arrives and gets routed to channel 2 because it has the fewest active streams.
The bind call returns 5 new affinity keys that is bound to channel 2:
Another bind call arrives and gets another 5 new keys:
This pattern may be continued to incur more imbalance.
If the upstream always requests the bind calls with a fixed number of affinity keys and never does unbind calls then we can round-robin bind calls to guarantee balanced distribution of affinity keys.
This PR introduces the option to round-robin bind calls.