Skip to content

Suboptimal performance on large buffers (sftp, stdin) #892

Closed

Description

@romanl-g

The following lines lead to suboptimal performance on large buffers.
A single _write or send typically sends ~32K bytes, while copying most of the remaining data passed in e.g. sftp.file.write(data) to a new buffer. If data is a few hundred MB, this can cap the transfer rate with 100% cpu usage.

Sftp: https://github.com/paramiko/paramiko/blob/master/paramiko/file.py#L499

while len(data) > 0:
    count = self._write(data)
    data = data[count:]

Stdin: https://github.com/paramiko/paramiko/blob/master/paramiko/channel.py#L814

while s:
    sent = self.send(s)
    s = s[sent:]

Sample benchmark on a 100MB buffer:

$ time python -c "a='0'*(100*1024*1024)
while a: a=a[32700:]"

21.92s user 15.02s system 99% cpu 36.982 total

Activity

  1. bz2 commented on Jun 6, 2017

    @bz2
    Contributor

    It's possible that with #971 passing a memoryview in will improve performance for some paths.

  2. added a commit that references this issue on Nov 15, 2018
    4aab829
  3. added a commit that references this issue on May 25, 2019
    4405f7c
  4. added a commit that references this issue on Jun 11, 2019
    57b2717
  5. added a commit that references this issue on Mar 28, 2020
    4f9449d
  6. bitprophet commented on Mar 7, 2022

    @bitprophet
    Member

    Should be fixed in b4bd81d

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