Skip to content

perf: send upload bodies in 1 MiB blocks instead of 16 KiB - #670

Open
patrick-immometrica wants to merge 1 commit into
Backblaze:masterfrom
patrick-immometrica:upload-send-blocksize
Open

patrick-immometrica wants to merge 1 commit into
Backblaze:masterfrom
patrick-immometrica:upload-send-blocksize

Conversation

@patrick-immometrica

Copy link
Copy Markdown

NotDecompressingHTTPAdapter doesn't set blocksize, so urllib3 uses its 16 KiB default and reads upload bodies 16 KiB at a time. A 100 MB part means ~6400 reads through ReadingStreamWithProgress -> StreamWithHash -> socket, all in Python with the GIL held, which hurts most when several upload threads run at once.

This sets it to 1 MiB for the pool manager and for proxy managers.

Rough numbers from a local sink over loopback HTTP, 64 MiB bodies through the real stream wrappers:

16 KiB 1 MiB
1 thread 1203 MB/s 2519 MB/s
8 threads 844 MB/s 8146 MB/s

On a slow link the network still dominates, but the CPU per uploaded byte drops either way. Progress callbacks now come in up to 1 MiB steps instead of 16 KiB.

urllib3 reads file-like bodies in 16 KiB chunks by default, so each
upload part went through StreamWithHash and the progress wrapper
thousands of times, with the GIL held.
@patrick-immometrica
patrick-immometrica marked this pull request as ready for review November 15, 2026 14:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant