Consolidate Batch client usage and decrease API hits #147
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.
This PR provides improvements on how PCTasks utilizes Azure Batch. This includes reducing the number of Batch clients created and the number of times the API is hit during a workflow run.
It modifies the RemoteWorkflowExecutor and TaskRunner to be context managers so that things like client connections can be managed by the class. The BatchTaskRunner now creates a batch client and uses a single client instead of creating and closing clients per call. This client is used across multiple threads, and thread safety from the client is assumed. This has been tested in multiple runs of a ~50 partition workflow.
In addition, a thread-locked cache is used to minimize the Batch API calls in the method that find failed Batch tasks. This method was being called once per thread, normally at roughly the same moment, and so would put a lot of pressure on the API. With the cache, the Batch API is hit at most a couple of times every 5 seconds for this purpose.