Skip to content

SFTP with Crypt backend does not utilize bandwidth #6763

Closed

Description

@sidamos

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

https://forum.rclone.org/t/rclone-transfer-rate-slower-than-rsync/34967/3

What is the problem you are having with rclone?

When I use SFTP plus Crypt, then it does not utilize my upload bandwidth. I have about 35 MBit upload speed, which should result in about 4 MBytes/s transfer.
If I use rsync plus encfs then I get 4 MBytes/s,
If I use rclone SFTP with Crypt, then I get only 2.6 MBytes/s.
If I use rclone SFTP without Crypt, then I get 4 MBytes/s.

CPU usage on my Core i5 is very low, so that is not the issue.

What is your rclone version (output from rclone version)

rclone v1.61.1

  • os/version: gentoo 2.9 (64 bit)
  • os/kernel: 5.15.88-gentoo-x86_64 (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.19.4
  • go/linking: static
  • go/tags: none

Which OS you are using and how many bits (e.g. Windows 7, 64 bit)

Linux 64 Bit. Gentoo.

Which cloud storage system are you using? (e.g. Google Drive)

SFTP to Hetzner storage box.

The command you were trying to run (e.g. rclone copy /tmp remote:tmp)

rclone sync localdir hetzner-crypt:/destdir --links --progress --transfers 9 --checkers 9 --check-first --create-empty-src-dirs --log-level ERROR

For testing rsync + encfs vs. rclone SFTP + Crypt, I transferred only one large file with one thread:

time rsync -Whav --progress --delete-after source dest
building file list ... 
2 files to consider
backup-test/
backup-test/rpi.img.gz_old
          1,60G 100%    3,71MB/s    0:06:51 (xfr#1, to-chk=0/2)

sent 1,60G bytes  received 37 bytes  3,88M bytes/sec
total size is 1,60G  speedup is 1,00

real    6m52,996s
user    0m5,595s
sys     0m2,648s
time ./rclone sync source dest --links --progress --transfers 1 --checkers 1 --check-first --create-empty-src-dirs
Transferred:        1.493 GiB / 1.493 GiB, 100%, 1.852 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:      9m45.1s

real    9m45,241s
user    0m16,047s
sys     0m6,916s

If I run rclone with for example 4 or 8 transfers on a real directory with mixed file sizes, I am seeing the same issue. Max total transfer rate I get is 2.6 MByte/s but should be up to 4 MByte/s.

Now rclone without Crypt:

time ./rclone sync source hetzner:/home/test/backup-test --links --progress --transfers 1 --checkers 1 --check-first --create-empty-src-dirs
Transferred:        1.492 GiB / 1.492 GiB, 100%, 3.188 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:      6m29.6s

real    6m29,639s
user    0m9,417s
sys     0m4,676s

Although rclone states 3.188 MiB/s as last number, it was near 4 MBytes/s during transfer and the total transfer time is good, too.

A log from the command with the -vv flag (e.g. output from rclone -vv copy /tmp remote:tmp)

2022/12/22 09:30:14 DEBUG : rclone: Version "v1.61.0" starting with parameters ["./rclone" "sync" "/work2/backup-test" "hetzner-crypt:/backup-test" "--links" "--progress" "--transfers" "1" "--checkers" "1" "--check-first" "--create-empty-src-dirs" "-vv" "--log-file" "rclone.log"]
2022/12/22 09:30:14 DEBUG : Creating backend with remote "/work2/backup-test"
2022/12/22 09:30:14 DEBUG : Using config file from "/root/.config/rclone/rclone.conf"
2022/12/22 09:30:14 DEBUG : local: detected overridden config - adding "{b6816}" suffix to name
2022/12/22 09:30:14 DEBUG : fs cache: renaming cache item "/work2/backup-test" to be canonical "local{b6816}:/work2/backup-test"
2022/12/22 09:30:14 DEBUG : Creating backend with remote "hetzner-crypt:/backup-test"
2022/12/22 09:30:14 DEBUG : Creating backend with remote "hetzner:rclone/t7sn3p3miij4fskh9s5hdk58og"
2022/12/22 09:30:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: New connection 192.168.0.2:36604->168.119.80.176:23 to "SSH-2.0-OpenSSH_8.8 FreeBSD-20211221"
2022/12/22 09:30:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Shell type "unix" from config
2022/12/22 09:30:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Relative path resolved to "/home/rclone/t7sn3p3miij4fskh9s5hdk58og"
2022/12/22 09:30:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Using root directory "/home/rclone/t7sn3p3miij4fskh9s5hdk58og"
2022/12/22 09:30:15 INFO  : Encrypted drive 'hetzner-crypt:/backup-test': Running all checks before starting transfers
2022/12/22 09:30:15 DEBUG : Encrypted drive 'hetzner-crypt:/backup-test': Waiting for checks to finish
2022/12/22 09:30:15 INFO  : Encrypted drive 'hetzner-crypt:/backup-test': Checks finished, now starting transfers
2022/12/22 09:30:15 DEBUG : Encrypted drive 'hetzner-crypt:/backup-test': Waiting for transfers to finish
2022/12/22 09:31:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:32:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:33:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:34:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:35:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:36:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:37:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:38:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:39:15 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Not closing 1 unused connections as 1 sessions active
2022/12/22 09:39:53 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Shell path "/home/rclone/t7sn3p3miij4fskh9s5hdk58og/9nu7j523t3t4uh4elp5ti9l850"
2022/12/22 09:39:53 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Running remote command: md5 -r /home/rclone/t7sn3p3miij4fskh9s5hdk58og/9nu7j523t3t4uh4elp5ti9l850
2022/12/22 09:39:59 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Remote command result: e64a7d5f2c2642b1e7dc83e74613e97f /home/rclone/t7sn3p3miij4fskh9s5hdk58og/9nu7j523t3t4uh4elp5ti9l850
2022/12/22 09:39:59 DEBUG : 9nu7j523t3t4uh4elp5ti9l850: Parsed hash: e64a7d5f2c2642b1e7dc83e74613e97f
2022/12/22 09:39:59 DEBUG : rpi.img.gz_old: md5 = e64a7d5f2c2642b1e7dc83e74613e97f OK
2022/12/22 09:39:59 INFO  : rpi.img.gz_old: Copied (new)
2022/12/22 09:39:59 DEBUG : Waiting for deletions to finish
2022/12/22 09:39:59 INFO  : 
Transferred:        1.493 GiB / 1.493 GiB, 100%, 1.840 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:      9m44.5s

2022/12/22 09:39:59 DEBUG : 12 go routines active
2022/12/22 09:39:59 DEBUG : sftp://[email protected]:23/rclone/t7sn3p3miij4fskh9s5hdk58og: Closing 1 unused connections

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 Feb 13, 2023

    @ncw
    Member

    I can replicate this problem locally with rclone's bandwidth limiter

    $ rclone copy 100M :sftp,user=sftptest: -v --bwlimit 10M
    2023/02/13 11:06:18 INFO  : Starting bandwidth limiter at 10Mi Byte/s
    2023/02/13 11:06:18 NOTICE: Can't save config "shell_type" for on the fly backend ":sftp"
    2023/02/13 11:06:18 NOTICE: Can't save config "md5sum_command" for on the fly backend ":sftp"
    2023/02/13 11:06:18 NOTICE: Can't save config "sha1sum_command" for on the fly backend ":sftp"
    2023/02/13 11:06:28 INFO  : 100M: Copied (new)
    2023/02/13 11:06:28 INFO  : 
    Transferred:   	      100 MiB / 100 MiB, 100%, 10.242 MiB/s, ETA 0s
    Transferred:            1 / 1, 100%
    Elapsed time:        10.2s
    

    Whereas

    $ rclone copy 100M 'secret,remote=":sftp,user=sftptest:secret":' -vv  --bwlimit 10M
    2023/02/13 11:07:09 INFO  : Starting bandwidth limiter at 10Mi Byte/s
    2023/02/13 11:07:09 DEBUG : rclone: Version "v1.62.0-beta.6731.63bf57580.s3-multipart-etag" starting with parameters ["rclone" "copy" "100M" "secret,remote=\":sftp,user=sftptest:secret\":" "-vv" "--bwlimit" "10M"]
    2023/02/13 11:07:09 DEBUG : Creating backend with remote "100M"
    2023/02/13 11:07:09 DEBUG : Using config file from "/home/ncw/.rclone.conf"
    2023/02/13 11:07:09 DEBUG : fs cache: adding new entry for parent of "100M", "/tmp"
    2023/02/13 11:07:09 DEBUG : Creating backend with remote "secret,remote=\":sftp,user=sftptest:secret\":"
    2023/02/13 11:07:09 DEBUG : secret: detected overridden config - adding "{54EvE}" suffix to name
    2023/02/13 11:07:09 DEBUG : Creating backend with remote ":sftp,user=sftptest:secret"
    2023/02/13 11:07:09 DEBUG : :sftp: detected overridden config - adding "{mH8_r}" suffix to name
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: New connection 127.0.0.1:56126->127.0.0.1:22 to "SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1"
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Running shell type detection remote command: echo ${ShellId}%ComSpec%
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Remote command result: %ComSpec%
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Shell type "unix" detected (set option shell_type to override)
    2023/02/13 11:07:09 DEBUG : Saving config "shell_type" in section ":sftp" of the config file
    2023/02/13 11:07:09 NOTICE: Can't save config "shell_type" for on the fly backend ":sftp"
    2023/02/13 11:07:09 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Relative path resolved to "/home/sftptest/secret"
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Using root directory "/home/sftptest/secret"
    2023/02/13 11:07:09 DEBUG : fs cache: renaming cache item ":sftp,user=sftptest:secret" to be canonical ":sftp{mH8_r}:secret"
    2023/02/13 11:07:09 DEBUG : fs cache: renaming cache item "secret,remote=\":sftp,user=sftptest:secret\":" to be canonical "secret{54EvE}:"
    2023/02/13 11:07:09 DEBUG : 100M: Need to transfer - File not found at Destination
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Checking default md5 hash commands
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Running remote command: md5sum
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Remote command result: d41d8cd98f00b204e9800998ecf8427e  -
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Hash command accepted
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Checking default sha1 hash commands
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Running remote command: sha1sum
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Remote command result: da39a3ee5e6b4b0d3255bfef95601890afd80709  -
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Hash command accepted
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Setting hash command for md5 to "md5sum" (set sha1sum_command to override)
    2023/02/13 11:07:09 DEBUG : Saving config "md5sum_command" in section ":sftp" of the config file
    2023/02/13 11:07:09 NOTICE: Can't save config "md5sum_command" for on the fly backend ":sftp"
    2023/02/13 11:07:09 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
    2023/02/13 11:07:09 DEBUG : sftp://sftptest@:22/secret: Setting hash command for sha1 to "sha1sum" (set md5sum_command to override)
    2023/02/13 11:07:09 DEBUG : Saving config "sha1sum_command" in section ":sftp" of the config file
    2023/02/13 11:07:09 NOTICE: Can't save config "sha1sum_command" for on the fly backend ":sftp"
    2023/02/13 11:07:09 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
    2023/02/13 11:07:24 DEBUG : sftp://sftptest@:22/secret: Shell path "/home/sftptest/secret/iqemg5cc4fr6p6jth2mhmja8f0"
    2023/02/13 11:07:24 DEBUG : sftp://sftptest@:22/secret: Running remote command: md5sum /home/sftptest/secret/iqemg5cc4fr6p6jth2mhmja8f0
    2023/02/13 11:07:24 DEBUG : sftp://sftptest@:22/secret: Remote command result: 909ba091791245f15246dcbadcfe1432  /home/sftptest/secret/iqemg5cc4fr6p6jth2mhmja8f0
    2023/02/13 11:07:24 DEBUG : iqemg5cc4fr6p6jth2mhmja8f0: Parsed hash: 909ba091791245f15246dcbadcfe1432
    2023/02/13 11:07:24 DEBUG : 100M: md5 = 909ba091791245f15246dcbadcfe1432 OK
    2023/02/13 11:07:24 INFO  : 100M: Copied (new)
    2023/02/13 11:07:24 INFO  : 
    Transferred:   	  100.024 MiB / 100.024 MiB, 100%, 6.787 MiB/s, ETA 0s
    Transferred:            1 / 1, 100%
    Elapsed time:        15.2s
    
    2023/02/13 11:07:24 DEBUG : 15 go routines active
    2023/02/13 11:07:24 DEBUG : sftp://sftptest@:22/secret: Closing 1 unused connections
    

    Whatever values I plug in for the bandwidth limiter, or even trying it without the bandwidth limiter I the crypt transfer is about 65% of the speed of the non crypt transfer which is what you are seeing.

    I discovered that lowering --sftp-chunk-size from the default 32k makes things run faster. At 4k it runs at 90% of the speed.

    I wonder whether this is a bad interaction between the crypt block size of 65568 and the chunk size...

    Setting --sftp-chunk-size 32784b (exactly half the crypt blocksize) puts it to 100% of the speed.

    I wonder if we are transmitting more data than we need to. This should be easy enough to measure with

    sudo tcpdump -i lo -n port 22 | grep 127.0.0.1.22: | perl -lne '$size += $1 if /length (\d+)/; print $size;'
    

    If I put the --sftp-chunk-size 64k then it runs at 50% of the speed as it is as if it is transmitting two 64k blocks, one which is mostly empty.

    A bit of work with tcpdump and perl later, I believe we are transmitting twice as much data as we should in this case. For a 100MiB file with --sftp-chunk-size 64k we transmit 200.7 MiB of data, but with --sftp-chunk-size 32784b 100.7 MiB and with default chunk size 150.8 MiB. Note that 100/150.8 is 66% so the ratio we've been seeing.

    OK, so that is what is happening. Why is a different question. This may be a bug in the SFTP library or in rclone.

    To be continued...

  2. ncw commented on Feb 13, 2023

    @ncw
    Member

    This turned out to be a bug in pkg/sftp which I've sent in a pull request to fix pkg/sftp#537

    In the mean time you should find setting --sftp-chunk-size 32784b is a reasonable work-around.

    When this gets merged upstream, I'll make a beta for you to try.

  3. sidamos commented on Feb 13, 2023

    @sidamos
    Author

    Wow, very cool. I can confirm that the workaround helps. I get 4 MBytes/s with it. Thank you!

  4. ncw commented on Feb 14, 2023

    @ncw
    Member

    Ok the upstream has merged my fix, and I've pulled it back into rclone.

    Can you give this a test please without a --sftp-chunk-size parameter.

    Thanks

    v1.62.0-beta.6731.3d4b4516c.fix-6763-sftp-slow on branch fix-6763-sftp-slow (uploaded in 15-30 mins)

    PS Thanks for being persistent about this bug :-)

  5. sidamos commented on Feb 14, 2023

    @sidamos
    Author

    Yes, I can confirm that the beta is fast without the --sftp-chunk-size parameter. Thank you!

  6. ncw commented on Feb 14, 2023

    @ncw
    Member

    Thank you for testing.

    I've merged this to master now which means it will be in the latest beta in 15-30 minutes and released in v1.62

  7. added a commit that references this issue on Feb 23, 2023
    80c505e
  8. added a commit that references this issue on Jan 30, 2024
    d4d7a6a
  9. added a commit that references this issue on Jul 20, 2026
    7b3d46a
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions