Skip to content

feat(upload): Enable compression for forwarded uploads#5965

Open
jjbayer wants to merge 6 commits intomasterfrom
feat/upload-compression
Open

feat(upload): Enable compression for forwarded uploads#5965
jjbayer wants to merge 6 commits intomasterfrom
feat/upload-compression

Conversation

@jjbayer
Copy link
Copy Markdown
Member

@jjbayer jjbayer commented May 8, 2026

Relay-to-Relay communication of upload streams did not use any compression. This PR makes it use the configured http.encoding (defaults to zstd).

This should be an overall win, but it should also remedy a specific case:

  1. Client enables compression (e.g. Content-Encoding: gzip).
  2. Client sends a payload that has a small compressed size but a large decompressed size.
  3. Relay reads the entire request body in a short time frame, but takes longer to transmit the bytes to the upstream because the data is now uncompressed.
  4. nginx does not receive any response and runs into a proxy_read_timeout.

Next steps after this PR: potentially enable compression for uploads to objectstore as well.

ref: INGEST-901

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 8, 2026

INGEST-901

jjbayer and others added 4 commits May 8, 2026 19:45
Replace the hardcoded gzip encoder in `UploadRequest::build` with a
dispatch over `config.http_encoding()`, so forwarded uploads can use
deflate/brotli/zstd in addition to gzip. Fixes the `encode_body` helper
to compile (proper stream bounds, boxed return type) and corrects a
ZstdDecoder/Encoder typo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This reverts commit f78c3a6.
@jjbayer jjbayer changed the title feat(upload): Enable compression for forwarded uplaods feat(upload): Enable compression for forwarded uploads May 8, 2026
@jjbayer jjbayer marked this pull request as ready for review May 8, 2026 18:59
@jjbayer jjbayer requested a review from a team as a code owner May 8, 2026 18:59
Comment thread Cargo.toml
# Keep it pinned until it's possible to disable backtrace.
anyhow = "=1.0.69"
arc-swap = "1"
async-compression = { version = "0.4", features = ["tokio", "gzip", "brotli", "deflate", "zstd"] }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already in our dependency tree.

kind: RequestKind::Upload {
location,
stream: Some(stream),
encoding: HttpEncoding::Zstd,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
encoding: HttpEncoding::Zstd,
encoding: HttpEncoding::Zstd, // just a default, will be overwritten by .configure()

Comment on lines +7 to +10
use async_compression::tokio::bufread::BrotliEncoder;
use async_compression::tokio::bufread::DeflateEncoder;
use async_compression::tokio::bufread::GzipEncoder;
use async_compression::tokio::bufread::ZstdEncoder;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use async_compression::tokio::bufread::BrotliEncoder;
use async_compression::tokio::bufread::DeflateEncoder;
use async_compression::tokio::bufread::GzipEncoder;
use async_compression::tokio::bufread::ZstdEncoder;
use async_compression::tokio::bufread::{BrotliEncoder, DeflateEncoder, GzipEncoder, ZstdEncoder};

Comment on lines +32 to +33
use tokio_util::io::ReaderStream;
use tokio_util::io::StreamReader;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use tokio_util::io::ReaderStream;
use tokio_util::io::StreamReader;
use tokio_util::io::{ReaderStream, StreamReader};

@loewenheim
Copy link
Copy Markdown
Contributor

Sorry, I had some comments based on misunderstandings, but I deleted them.

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.

2 participants