Use shared ProcessPoolExecutor across all services #1157
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.
revamp of #1155
What was wrong?
fixes #1076
In the chain and state syncers there is an API for running computationally heavy workloads in a process pool of workers. The worker pool is automatically sized according to the number of cpus available on the machine. This pattern is quite useful, however, if used concurrently by two services, it would result in multiple pools being created, and would likely overwhelm the CPU load on the machine.
How was it fixed?
The
_run_in_executor
API is now available for allBaseService
subclasses. This implements a quick-and-easy solution using a global executor pool which will be re-used across allBaseService
subclasses within a single process.This PR also contains additional cleanup:
BasePeer
class is now instantiated with the cancel token from thePeerPool
.BaseService.loop
in the various asyncio APIs.Cute Animal Picture