Multi-thread copies from a local source hand the chunk writer an
unbuffered ReOpen. Backends such as s3, azureblob and
oracleobjectstorage checksum the chunk with io.Copy before uploading
it, and as ReOpen didn't implement io.WriterTo, io.Copy read the file
in 32 KiB pieces.
ReOpen now implements io.WriterTo:
- If the destination implements io.ReaderFrom, that is used so the
destination's own buffering is kept. This means multi-thread
downloads (bufio.Writer over an OffsetWriter, sized by
--multi-thread-write-buffer-size) and HTTP request bodies behave as
before and don't gain an extra buffer.
- If less than 1 MiB remains it uses io.Copy as before, so small files
don't take a 1 MiB buffer.
- Otherwise it copies through a 1 MiB buffer from the global pool, so
the memory is reused and is counted by --max-buffer-memory.
This replaces the s3 specific io.CopyBuffer from a68480093 (reverted
in the previous commit) which allocated a fresh 1 MiB buffer for every
chunk outside of --max-buffer-memory, and gives the same speedup to
every backend which io.Copies from the chunk reader.
Benchmarks on Linux, 16 cores, source file on tmpfs, warm cache.
"orig" is master with a68480093 reverted (32 KiB reads), "master" has
a68480093 (make 1 MiB per chunk), "branch" is this commit.
Checksum pass only - ReOpen of a local 128 MiB range into md5, 5 runs:
1 stream MB/s B/op
orig 752-759 34 KiB
master 751-784 1025 KiB
branch 764-784 1.2 KiB
16 streams MB/s B/op
orig 4772-5495 547 KiB
master 4008-4607 16405 KiB
branch 4525-5052 22 KiB
On Linux the reads are cheap so the larger reads are worth ~2-3% for
a single stream and are lost in the noise with 16 streams. The point
here is that branch matches master's reads without allocating.
The same benchmark on Windows 10 (VirtualBox VM, 8 vCPUs on a Ryzen 7
PRO 5850U, 64 MiB chunk per stream, 1 GiB file in the file cache),
where reads are more expensive, shows the speedup. Median of 5 runs:
streams orig master branch
1 560 MB/s 594 MB/s (+6.1%) 610 MB/s (+9.0%)
4 1438 MB/s 1594 MB/s (+10.9%) 1610 MB/s (+12.0%)
8 1878 MB/s 2123 MB/s (+13.0%) 2143 MB/s (+14.1%)
allocated per op (all streams)
1 33 KiB 1026 KiB 1 KiB
4 134 KiB 4102 KiB 5 KiB
8 267 KiB 8204 KiB 10 KiB
With 4 and 8 streams the ranges of orig and branch don't overlap.
End to end - rclone copy of a 2 GiB local file to MinIO on localhost
(server bound, so wall time doesn't change), mean of 4 runs, max RSS
and number of GCs from GODEBUG=gctrace=1:
default (5 MiB chunks, 4 streams)
wall max RSS GCs
orig 6.13s 84 MiB 14
master 6.29s 93 MiB 54
branch 6.30s 90 MiB 8
--s3-upload-concurrency 16 --s3-chunk-size 64M
wall max RSS GCs
orig 4.76s 83 MiB 6
master 4.80s 112 MiB 7
branch 4.80s 97 MiB 6
Multi-thread download of the same file from MinIO to local disk
(checks the io.ReaderFrom path), mean of 4 runs:
wall max RSS GCs
orig 4.31s 80 MiB 5
master 4.31s 80 MiB 5
branch 4.32s 80 MiB 5
Uploads with --max-buffer-memory 2M and 4M (with
--s3-upload-concurrency 16 --s3-chunk-size 64M) complete normally in
5-7s, throttled rather than stalled.