Re-use connections when remote S3 signing #2543
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.
Rationale for this change
The existing S3 remote signing hook function (
s3v4_rest_signer) usesrequests.postto submitPOSTrequests to the REST signing endpoint. This internally creates a newrequests.Sessionfor every request, preventing any reuse of connections.In my profiling I saw this add overhead from repeated loading of CA certs and reestablishing of TLS connections.
This change makes the signing function a callable object that wraps a
request.Session, using this forPOSTing, therefore achieving connection reuse.Signer callables are stored on the hook internals of the
aiobotocoreclient inside thes3fs.S3FileSysteminstance, so use and lifetime will match that of those instances. They are thread-local since: #2495.Are these changes tested?
Tested locally. Existing unit tests updated for changes.
Are there any user-facing changes?
Yes - S3 signing requests now use connection pools (scoped to the
s3fs.S3FileSystemobject).