Skip to content

Awful performance due to reading bytes 1 at a time #819

Closed

Description

@Dreamsorcerer

I'm using fabric to send a stream of binary data (can be GBs in size). The invoke code reads the data 1 byte at a time. This seems to result in an upload speed maxing out at 10KB/s, which would take days to upload the necessary data.

Perhaps there can be a way to customise the chunk size for reading?

I easily achieved over 2MB/s after changing that number (atleast 200x improvement, probably more if I had a faster internet connection):

--- a/invoke/runners.py
+++ b/invoke/runners.py
@@ -790,13 +790,13 @@ class Runner(object):
         # read instead of once per session, which could be costly (?).
         bytes_ = None
         if ready_for_reading(input_):
-            bytes_ = input_.read(bytes_to_read(input_))
+            bytes_ = input_.read(2**20)
             # Decode if it appears to be binary-type. (From real terminal
             # streams, usually yes; from file-like objects, often no.)

Activity

  1. bitprophet commented on May 12, 2023

    @bitprophet
    Member

    See #915 where we are discussing solutions to this.

  2. Dreamsorcerer commented on May 12, 2023

    @Dreamsorcerer
    ContributorAuthor

    Sorry, mixing up issues. #915 solves #818. This is a separate issue (encountered in the same application I developed). I haven't proposed a solution to this yet, though the obvious thing is to add a chunk_size parameter somewhere.

  3. pgimalac commented on Jul 3, 2025

    @pgimalac

    I'm not sure #915 is quite the same issue, I'm also having performance issues with reading stdin and it's unrelated to encoding, the issue is just that bytes_to_read always returns 1...

    I was able to work around that by using a custom reader which ignores the size argument and returns 10MiB at a time, not a clean solution but good enough for now.

  4. Dreamsorcerer commented on Jul 3, 2025

    @Dreamsorcerer
    ContributorAuthor

    I'm not sure #915 is quite the same issue

    It's not related, I already mentioned that. @bitprophet was mixing up conversations.

    I was able to work around that by using a custom reader which ignores the size argument and returns 10MiB at a time, not a clean solution but good enough for now.

    Currently, I just have a bunch of patches locally over these libraries in order to make them usable..

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