Skip to content

Reduce RAM usage by relying on temp files #7350

Closed

Description

@maxim

The associated forum post URL from https://forum.rclone.org

https://forum.rclone.org/t/1-64-0-and-latest-beta-1-65-0-both-crash-on-rclone-crypt-sync-b2-on-large-files/41987

What is your current rclone version (output from rclone version)?

rclone v1.65.0-beta.7391.55c3c221b.fix-b2-upload-url-lock
- os/version: ubuntu 22.04 (64 bit)
- os/kernel: 5.15.0-84-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.21.1
- go/linking: static
- go/tags: none

What problem are you are trying to solve?

Rclone currently stores chunks in RAM. Recently, RAM usage increased for B2 users, when a refactor changed the RAM formula from

--transfers * --b2-chunk-size

to

--transfers * --b2-chunk-size * --b2-upload-concurrency

A possible way to reduce RAM usage across the board is to move most chunk manipulations into temporary files on disk.

How do you think rclone should be changed to solve that?

To summarize the forum post, we could add an alternative implementation of io.ReadSeeker interface, that reads disk (file handles) rather than objects in RAM.

In a more abstract framing: any chunk-data operation that writes/reads RAM could instead do so with temporary files on disk. This includes activity such as caching data coming from network, and hashing data to calculate checksums. Every chunk manipulation should be done via streaming to/from temporary files rather than RAM.

This behavior could be exposed to an end user as an option such as --low-memory or the opposite --slow-disk, depending on which mode ends up being the default.

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Activity

  1. ncw commented on Oct 3, 2023

    @ncw
    Member

    I see 3 possible buffering schemes

    1. RAM: Buffer in RAM like we have at the moment
    2. Disk: Buffer on disk as suggested here
    3. None: Don't buffer, but re-read from the source if necessary.

    The b2 backend only rewinds the stream if there is a retry. Retries are rare, so we could use scheme None when uploading to b2. (We need a backend feature to identify this, or maybe a parameter in the chunking protocol.)

    If we are using local as a source we could also use None for all backends as buffering to disk doesn't seem sensible when the file is on disk anyway.

    Exactly which scheme gets used is up for discussion, but here is my suggestion

    Source backend Destination backend High Memory Low Memory
    local any None¹ None
    any local None² None
    any b2 None None
    any s3/azureblob/oos RAM Disk

    ¹ Needs performance testing to see if it slows stuff down a lot! Might need to be RAM

    ² It works like this at the moment as the local backend never needs retries.

    Implementing the None scheme requires extending operations.Open to into a ReadSeeker. This isn't a lot of work.

  2. ncw commented on Oct 8, 2023

    @ncw
    Member

    I had a go at this in the "High Memory" case above. Most transfers (which are to and from disk) won't need to use buffering any more which is a big win.

    @maxim can you give this a test and see what you think?

    v1.65.0-beta.7413.87aa029f5.fix-7350-multithread-memory on branch fix-7350-multithread-memory (uploaded in 15-30 mins)

  3. maxim commented on Oct 8, 2023

    @maxim
    Author

    @ncw Looks like a great win in a small change! To try this, I have questions on what I should reconfigure:

    1. What is the new RAM usage math for B2 uploads? (Values such as --b2-upload-concurrency, --b2-chunk-size, --transfers, --multi-thread-streams).
    2. What is the new math for B2 downloads? (Values such as --buffer-size, --transfers, --multi-thread-streams)
    3. Do you know if reconfiguring will invalidate my vfs full cache again (the canonical name) and how to avoid that?
  4. ncw commented on Oct 8, 2023

    @ncw
    Member

    @ncw Looks like a great win in a small change! To try this, I have questions on what I should reconfigure:

    1. What is the new RAM usage math for B2 uploads? (Values such as --b2-upload-concurrency, --b2-chunk-size, --transfers, --multi-thread-streams).

    Uploads from local disk to B2 shouldn't use significantly extra ram whatever the parameters.

    1. What is the new math for B2 downloads? (Values such as --buffer-size, --transfers, --multi-thread-streams)

    Downloads will use --buffer-size * --transfers

    1. Do you know if reconfiguring will invalidate my vfs full cache again (the canonical name) and how to avoid that?

    Put any B2 config changes in the config file, not on the command line and it won't change the canonical name.

  5. maxim commented on Oct 9, 2023

    @maxim
    Author

    Thanks for clarifications. I installed this branch without changing config for now. Will have to wait and see as more uploads take place.

  6. ncw commented on Oct 9, 2023

    @ncw
    Member

    Let me know what happens!

  7. maxim commented on Oct 12, 2023

    @maxim
    Author

    @ncw After 3 days of running, which included downloads and uploads, rclone seems to have been sitting at <50mb of RAM, even according to systemctl status (which tends to show the highest RAM ever reached, or something like that). It appears so far that this is working!

    We could wait until I observe RAM directly during an upload. I think I caught it once, and it was still under 50mb, but not 100% sure. Would have to catch it one of these days. It has definitely uploaded stuff over 3 days, but I just haven't observed as it was happening.

  8. added this to the v1.65 milestone on Nov 3, 2023
  9. added a commit that references this issue on Jan 26, 2024
    1f9a79e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions