Implement concurrent directory transfer in SFTPOperator#47533
Merged
potiuk merged 5 commits intoApr 8, 2025
Conversation
Adaverse
reviewed
Mar 9, 2025
potiuk
approved these changes
Apr 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 implements concurrent directory transfer functions for the SFTP Operator.
The SFTP hook now includes two new functions,
retrieve_directory_concurrentlyandstore_directory_concurrently, which are concurrent versions of the existing ones,retrieve_directoryandstore_directory. They utilize multi-threading via Python’sconcurrent.futures, resulting in a significant speed improvement when moving a directory containing thousands of files. Also, each thread opens a new connection and transfers a chunk of files assigned to it since the paramiko library is not thread-safe.The SFTP operator now has a new parameter,
concurrency, and uses the concurrent version of the hook file when this value is greater than 1. It continues to use the existing sequential version when the value is 1.I tested it by transferring a directory containing 1,000 small files. The results showed a dramatic performance improvement: storing the directory decreased from approximately 24 seconds to 2 seconds, and retrieving it decreased from about 42 seconds to 4 seconds.