Skip to content

use SFTPClient's get method to download big file from sftp server will block #1779

Closed

Description

@cfh0081

Use SFTPClient's get method to download big file from sftp server will block. The error stack information as below:
sftp_download_error_stack_20201118.txt
I found the problem is here:

python3.6\Lib\site-packages\paramiko\sftp_file.py

    def _prefetch_thread(self, chunks):
        # do these read requests in a temporary thread because there may be
        # a lot of them, so it may block.
        for offset, length in chunks:
            num = self.sftp._async_request(
                self, CMD_READ, self.handle, long(offset), int(length)
            )
            with self._prefetch_lock:
                self._prefetch_extents[num] = (offset, length)

too many requests at same time. And my solution as below:

python3.6\Lib\site-packages\paramiko\sftp_file.py

    def _prefetch_thread(self, chunks):
        # do these read requests in a temporary thread because there may be
        # a lot of them, so it may block.
        max_request_num = 512
        to_wait = False
        for offset, length in chunks:
            num = self.sftp._async_request(
                self, CMD_READ, self.handle, long(offset), int(length)
            )
            with self._prefetch_lock:
                self._prefetch_extents[num] = (offset, length)
                if len(self._prefetch_extents) >= max_request_num:
                    to_wait = True
            
            if to_wait:
                time.sleep(1)
                to_wait = False

I hope the official version can fix the problem with an appropriate concurrency number limit and this number is configurable. Or use a better solution to solve the problem. Thank you!

Activity

  1. bitprophet commented on Jun 9, 2023

    @bitprophet
    Member

    Rolling into #2058 - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions