Replace pool with single gRPC client #88
Merged
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.
Improve gRPC performance and stability by getting rid of the connections pool in favor of the built-in streaming and multiplexing provided by the grpc package.
Benchmarks show that using a single client result in less errors and slightly better performance than using a pool.
Also, retry mechanism has been also improved to handle exhausted and unavailable errors differently: when we receive ResourceExhausted we try to re-run the request almost immediately. The reason is that we assume that the concurrency settings for the client and the server are similar (though not equal, see below), thus, there could not be real exhaustion but the lag in server implementation (it looks like the worker is returned to the pool after the request completed, so there is a little gap).
For the same reason we set (and recommend setting) the default concurrency for RPC client to be a slightly less than the number of workers in the server (the corresponding defaults are 28 < 30).