Skip to content

Conversation

@shangm2
Copy link
Contributor

@shangm2 shangm2 commented Oct 21, 2025

Description

  1. add data compression support for http2. zstd only for better performance.
  2. all parameters are configurable
  3. will only be enabled if configured properly
  4. work together with chore: Add http2 data compression for cpp worker #26382

Motivation and Context

  1. when communicating with cpp worker via http2, coordinator will compress both the header and body and will also receive compressed response. We see great compression ratio for payload greater than 8 kB.

Impact

Test Plan

  1. passed verifier run

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* Add data compression support for http2 protocol

@shangm2 shangm2 requested a review from a team as a code owner October 21, 2025 14:39
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Oct 21, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 21, 2025

Reviewer's Guide

This PR implements optional zstd-based compression for HTTP2 task update requests and responses, adds configurable compression and TCP buffer settings in ReactorNettyHttpClientConfig, applies these settings in ReactorNettyHttpClient initialization (enabling HTTP compression and buffer options), injects per-request logic to compress POST bodies when thresholds are met, and adds the zstd-jni dependency.

Sequence diagram for POST request compression in ReactorNettyHttpClient

sequenceDiagram
    participant Coordinator
    participant "ReactorNettyHttpClient"
    participant "ZstdOutputStreamNoFinalizer"
    participant "HTTP2 Worker"
    Coordinator->>"ReactorNettyHttpClient": send POST request (body)
    alt Compression enabled & body >= threshold
        "ReactorNettyHttpClient"->>"ZstdOutputStreamNoFinalizer": compress body
        "ZstdOutputStreamNoFinalizer"-->>"ReactorNettyHttpClient": compressed body
        "ReactorNettyHttpClient"->>"HTTP2 Worker": POST (compressed body, header Content-Encoding: zstd)
    else Compression not enabled or body < threshold
        "ReactorNettyHttpClient"->>"HTTP2 Worker": POST (original body)
    end
Loading

Entity relationship diagram for new configuration properties in ReactorNettyHttpClientConfig

erDiagram
    REACTOR_NETTY_HTTP_CLIENT_CONFIG {
        boolean dataCompressionEnabled
        int dataCompressionThreshold
        double useCompressedDataThreshold
        int tcpBufferSize
    }
Loading

Class diagram for updated ReactorNettyHttpClientConfig and ReactorNettyHttpClient

classDiagram
    class ReactorNettyHttpClientConfig {
        +boolean dataCompressionEnabled
        +DataSize dataCompressionThreshold
        +double useCompressedDataThreshold
        +DataSize tcpBufferSize
        +setDataCompressionEnabled(boolean)
        +isDataCompressionEnabled() boolean
        +getUseCompressedDataThreshold() double
        +setUseCompressedDataThreshold(double) ReactorNettyHttpClientConfig
        +getTcpBufferSize() int
        +setTcpBufferSize(DataSize) ReactorNettyHttpClientConfig
        +getDataCompressionThreshold() int
        +setDataCompressionThreshold(DataSize) ReactorNettyHttpClientConfig
    }
    class ReactorNettyHttpClient {
        -boolean isDataCompressionEnabled
        -int dataCompressionThreshold
        -double useCompressedDataThreshold
        +ReactorNettyHttpClient(ReactorNettyHttpClientConfig, HttpClientConnectionPoolStats, HttpClientStats)
    }
    ReactorNettyHttpClientConfig <|-- ReactorNettyHttpClient
Loading

File-Level Changes

Change Details Files
Introduce configurable data compression and TCP buffer properties
  • Add boolean flag for enabling data compression
  • Define compression threshold and compression-ratio threshold with config annotations
  • Introduce tcpBufferSize property with constraints and config setter
ReactorNettyHttpClientConfig.java
Apply compression and buffer settings during HTTP client initialization
  • Inject config flags and thresholds into ReactorNettyHttpClient
  • Enable HTTP-level compression (.compress(true))
  • Configure channel options for send/receive buffers and water marks based on tcpBufferSize
ReactorNettyHttpClient.java
Compress POST request body with zstd when enabled and beneficial
  • Check payload size and enabled flag before compression
  • Compress bytes via ZstdOutputStreamNoFinalizer and compute compression ratio
  • Conditionally set compressed body and add Content-Encoding header
  • Fallback with logging on compression failure
ReactorNettyHttpClient.java
Add zstd-jni library dependency
  • Include com.github.luben:zstd-jni in pom.xml dependencies
pom.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@shangm2 shangm2 changed the title Add suppport to compress the task update request header and body Add compression support the task update request header and body Oct 21, 2025
@shangm2 shangm2 changed the title Add compression support the task update request header and body Add compression support for task update request header and body Oct 21, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `presto-main/src/main/java/com/facebook/presto/server/remotetask/ReactorNettyHttpClient.java:250` </location>
<code_context>
+                        }
+
+                        byte[] compressedBytes = baos.toByteArray();
+                        double compressionRatio = (double) (postBytes.length - compressedBytes.length) / postBytes.length;
+                        if (compressionRatio >= useCompressedDataThreshold) {
+                            bodyToSend = compressedBytes;
</code_context>

<issue_to_address>
**issue (bug_risk):** Compression ratio calculation may be negative if compressedBytes is larger than postBytes.

Negative compressionRatio values may cause compressed data to be used when it is actually larger than the original. Ensure the ratio is non-negative, for example by using Math.max(0, compressionRatio).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

byte[] compressedBytes = baos.toByteArray();
double compressionRatio = (double) (postBytes.length - compressedBytes.length) / postBytes.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Compression ratio calculation may be negative if compressedBytes is larger than postBytes.

Negative compressionRatio values may cause compressed data to be used when it is actually larger than the original. Ensure the ratio is non-negative, for example by using Math.max(0, compressionRatio).

@shangm2 shangm2 changed the title Add compression support for task update request header and body Add compression support for reactor-netty http2 client Oct 21, 2025
@shangm2 shangm2 changed the title Add compression support for reactor-netty http2 client [chore]Add compression support for reactor-netty http2 client Oct 24, 2025
@shangm2 shangm2 changed the title [chore]Add compression support for reactor-netty http2 client chore: Add compression support for reactor-netty http2 client Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:Meta PR from Meta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants