You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Dawnpool (via GitHub)" <gi...@apache.org> on 2025/03/08 13:38:09 UTC

[PR] Implement concurrent directory transfer in SFTPOperator [airflow]

Dawnpool opened a new pull request, #47533:
URL: https://github.com/apache/airflow/pull/47533

   This PR implements concurrent directory transfer functions for the SFTP Operator.
   
   The SFTP hook now includes two new functions, `retrieve_directory_concurrently` and `store_directory_concurrently`, which are concurrent versions of the existing ones. They utilize multi-threading via Python’s `concurrent.futures`, resulting in a significant speed improvement. 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.**


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Implement concurrent directory transfer in SFTPOperator [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #47533:
URL: https://github.com/apache/airflow/pull/47533


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Implement concurrent directory transfer in SFTPOperator [airflow]

Posted by "Dawnpool (via GitHub)" <gi...@apache.org>.
Dawnpool commented on code in PR #47533:
URL: https://github.com/apache/airflow/pull/47533#discussion_r1988239758


##########
providers/sftp/src/airflow/providers/sftp/operators/sftp.py:
##########
@@ -171,9 +185,17 @@ def execute(self, context: Any) -> str | list[str] | None:
                         file_msg = f"from {_local_filepath} to {_remote_filepath}"
                         self.log.info("Starting to transfer file %s", file_msg)
                         if os.path.isdir(_local_filepath):
-                            self.sftp_hook.store_directory(
-                                _remote_filepath, _local_filepath, confirm=self.confirm
-                            )
+                            if self.concurrency > 1:
+                                self.sftp_hook.store_directory_concurrently(
+                                    _remote_filepath,
+                                    _local_filepath,
+                                    confirm=self.confirm,
+                                    workers=self.concurrency,
+                                )
+                            elif self.concurrency == 1:

Review Comment:
   Hi @Adaverse , Thanks for your comment.
   Since the `local_filepath` and `remote_filepath` parameters already accept a list of strings, users can already pass multiple files at once. Did you mean adding concurrency not only for directory but also for passing multiple files as well? If so, I think there should be quite a lot structural changes in the operator code.
   I'd prefer to focus only on directory transfer in this PR. Once this is merged, I can create a separate PR for your suggestion.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Implement concurrent directory transfer in SFTPOperator [airflow]

Posted by "Adaverse (via GitHub)" <gi...@apache.org>.
Adaverse commented on code in PR #47533:
URL: https://github.com/apache/airflow/pull/47533#discussion_r1986185947


##########
providers/sftp/src/airflow/providers/sftp/operators/sftp.py:
##########
@@ -171,9 +185,17 @@ def execute(self, context: Any) -> str | list[str] | None:
                         file_msg = f"from {_local_filepath} to {_remote_filepath}"
                         self.log.info("Starting to transfer file %s", file_msg)
                         if os.path.isdir(_local_filepath):
-                            self.sftp_hook.store_directory(
-                                _remote_filepath, _local_filepath, confirm=self.confirm
-                            )
+                            if self.concurrency > 1:
+                                self.sftp_hook.store_directory_concurrently(
+                                    _remote_filepath,
+                                    _local_filepath,
+                                    confirm=self.confirm,
+                                    workers=self.concurrency,
+                                )
+                            elif self.concurrency == 1:

Review Comment:
   How about extending this feature to allow users to pass multiple different files at once as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org