Skip to content

Commit 125ea08

Browse files
committed
Add support for OpenSSH "limits" extension
This commit adds client and server support for the OpenSSH "limits" extension, which allows the client to query server limits such as the maximum supported read and write size, improving performance between clients and servers that can support larger sizes. When AsyncSSH is acting as a server, it advertises support for up to 4 MiB reads and write, and a large enough packet size to hold such write requests. As a client, it will query these values from servers supporting the extension and automatically default to the largest supported size. When a server does not support this extension, AsyncSSH will fall back to a "safe" maxmium size of 16 KiB for both reads and writes. SCP has also been adjusted from a default size of 16 KiB to 256 KiB, which seemed to be the sweet spot after some local performance testing. As before, callers can always choose to override this default with the block_size parameter on calls to open() or to the higher-level get/put/copy functions, but generally speaking this should not be necessary.
1 parent 8fdce8a commit 125ea08

File tree

3 files changed

+208
-71
lines changed

3 files changed

+208
-71
lines changed

asyncssh/scp.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from .sftp import SFTPAttrs, SFTPGlob, SFTPName, SFTPServer, SFTPServerFS
4343
from .sftp import SFTPFileProtocol, SFTPError, SFTPFailure, SFTPBadMessage
4444
from .sftp import SFTPConnectionLost, SFTPErrorHandler, SFTPProgressHandler
45-
from .sftp import SFTP_BLOCK_SIZE, local_fs
45+
from .sftp import local_fs
4646

4747

4848
if TYPE_CHECKING:
@@ -57,6 +57,9 @@
5757
_SCPConnPath = Union[Tuple[_SCPConn, _SCPPath], _SCPConn, _SCPPath]
5858

5959

60+
_SCP_BLOCK_SIZE = 256*1024 # 256 KiB
61+
62+
6063
class _SCPFSProtocol(Protocol):
6164
"""Protocol for accessing a filesystem during an SCP copy"""
6265

@@ -409,7 +412,7 @@ class _SCPSource(_SCPHandler):
409412

410413
def __init__(self, fs: _SCPFSProtocol, reader: 'SSHReader[bytes]',
411414
writer: 'SSHWriter[bytes]', preserve: bool, recurse: bool,
412-
block_size: int = SFTP_BLOCK_SIZE,
415+
block_size: int = _SCP_BLOCK_SIZE,
413416
progress_handler: SFTPProgressHandler = None,
414417
error_handler: SFTPErrorHandler = None, server: bool = False):
415418
super().__init__(reader, writer, error_handler, server)
@@ -568,7 +571,7 @@ class _SCPSink(_SCPHandler):
568571

569572
def __init__(self, fs: _SCPFSProtocol, reader: 'SSHReader[bytes]',
570573
writer: 'SSHWriter[bytes]', must_be_dir: bool, preserve: bool,
571-
recurse: bool, block_size: int = SFTP_BLOCK_SIZE,
574+
recurse: bool, block_size: int = _SCP_BLOCK_SIZE,
572575
progress_handler: SFTPProgressHandler = None,
573576
error_handler: SFTPErrorHandler = None, server: bool = False):
574577
super().__init__(reader, writer, error_handler, server)
@@ -736,7 +739,7 @@ def __init__(self, src_reader: 'SSHReader[bytes]',
736739
src_writer: 'SSHWriter[bytes]',
737740
dst_reader: 'SSHReader[bytes]',
738741
dst_writer: 'SSHWriter[bytes]',
739-
block_size: int = SFTP_BLOCK_SIZE,
742+
block_size: int = _SCP_BLOCK_SIZE,
740743
progress_handler: SFTPProgressHandler = None,
741744
error_handler: SFTPErrorHandler = None):
742745
self._source = _SCPHandler(src_reader, src_writer)
@@ -898,7 +901,7 @@ async def run(self) -> None:
898901

899902
async def scp(srcpaths: Union[_SCPConnPath, Sequence[_SCPConnPath]],
900903
dstpath: _SCPConnPath = None, *, preserve: bool = False,
901-
recurse: bool = False, block_size: int = SFTP_BLOCK_SIZE,
904+
recurse: bool = False, block_size: int = _SCP_BLOCK_SIZE,
902905
progress_handler: SFTPProgressHandler = None,
903906
error_handler: SFTPErrorHandler = None, **kwargs) -> None:
904907
"""Copy files using SCP
@@ -955,7 +958,7 @@ async def scp(srcpaths: Union[_SCPConnPath, Sequence[_SCPConnPath]],
955958
SFTP instead.
956959
957960
The block_size value controls the size of read and write operations
958-
issued to copy the files. It defaults to 16 KB.
961+
issued to copy the files. It defaults to 256 KB.
959962
960963
If progress_handler is specified, it will be called after each
961964
block of a file is successfully copied. The arguments passed to

0 commit comments

Comments
 (0)