Skip to content

Commit 8fdce8a

Browse files
committed
Speed up parallelized SFTP reads when read size goes beyond end of file
This commit speeds up SFTP read calls when the requested read size is much larger than the size of the file. Instead of continuing to read past the end, the parallel read algorithm now stops issuing new read requests as soon as an earlier read completes with an EOF error. While calling read() with no length is still the best option if you want to read a whole file, this optimization may be helpful in some cases. Thanks go to Maximilian Knespel for reporting this issue and doing performance measurements on the code before and after the change!
1 parent a3a3b26 commit 8fdce8a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

asyncssh/sftp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ async def iter(self) -> AsyncIterator[Tuple[int, _T]]:
670670
self._pending.add(asyncio.ensure_future(
671671
self._start_task(offset+count, size-count)))
672672
except SFTPEOFError:
673-
pass
673+
self._bytes_left = 0
674674
except (OSError, SFTPError) as exc:
675675
exceptions.append(exc)
676676

0 commit comments

Comments
 (0)