Skip to content

Conversation

@Chaho12
Copy link
Member

@Chaho12 Chaho12 commented Sep 10, 2025

Description

Accept-Encoding is removed when making POST request so response does not include compression.
Since client(trino-gateway) requests without It compression, trino server would return without compression (Content-Encoding).

It may depend on result, but when it seems compression is done about 51%(722->351), so approx 51% of network/memory could be saved.

Additional context and related issues

local test

before (add request/response header logging from main branch)

2025-09-10T11:28:12.860+0900    INFO    http-worker-80  io.trino.gateway.ha.handler.RoutingTargetHandler        Rerouting [http://[0:0:0:0:0:0:0:1]:8080/v1/statement]--> [http://localhost:8082/v1/statement]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Request Headers:
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Accept] = [[*/*]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Content-Length] = [[480]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Content-Type] = [[application/json]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [User-Agent] = [[curl/8.7.1]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Via] = [[HTTP/1.1 TrinoGateway]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-For] = [[[0:0:0:0:0:0:0:1]]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Host] = [[localhost]]
2025-09-10T11:28:12.861+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Port] = [[8080]]
2025-09-10T11:28:12.862+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Proto] = [[http]]
2025-09-10T11:28:12.862+0900    INFO    http-worker-80  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Trino-User] = [[lago-hive]]
2025-09-10T11:28:12.885+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Response Headers:
2025-09-10T11:28:12.886+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Date] = [[Wed, 10 Sep 2025 02:28:12 GMT]]
2025-09-10T11:28:12.886+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Vary] = [[Accept-Encoding]]
2025-09-10T11:28:12.886+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Content-Type] = [[application/json]]
2025-09-10T11:28:12.886+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [X-Content-Type-Options] = [[nosniff]]
2025-09-10T11:28:12.886+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Content-Length] = [[722]]

after

2025-09-10T11:20:41.950+0900    INFO    http-worker-81  io.trino.gateway.ha.handler.RoutingTargetHandler        Rerouting [http://[0:0:0:0:0:0:0:1]:8080/v1/statement]--> [http://localhost:8082/v1/statement]
2025-09-10T11:20:41.951+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Request Headers:
2025-09-10T11:20:41.953+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Accept] = [[*/*]]
2025-09-10T11:20:41.953+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Accept-Encoding] = [[gzip, deflate, br]]
2025-09-10T11:20:41.953+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Content-Length] = [[480]]
2025-09-10T11:20:41.953+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Content-Type] = [[application/json]]
2025-09-10T11:20:41.953+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [User-Agent] = [[curl/8.7.1]]
2025-09-10T11:20:41.957+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [Via] = [[HTTP/1.1 TrinoGateway]]
2025-09-10T11:20:41.957+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-For] = [[[0:0:0:0:0:0:0:1]]]
2025-09-10T11:20:41.957+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Host] = [[localhost]]
2025-09-10T11:20:41.957+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Port] = [[8080]]
2025-09-10T11:20:41.957+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Forwarded-Proto] = [[http]]
2025-09-10T11:20:41.958+0900    INFO    http-worker-81  io.trino.gateway.proxyserver.ProxyRequestHandler        Header [X-Trino-User] = [[lago-hive]]
2025-09-10T11:20:41.997+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Response Headers:
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Date] = [[Wed, 10 Sep 2025 02:20:41 GMT]]
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Vary] = [[Accept-Encoding]]
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Content-Type] = [[application/json]]
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [X-Content-Type-Options] = [[nosniff]]
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Content-Encoding] = [[gzip]]
2025-09-10T11:20:41.998+0900    INFO    http-client-proxy-52    io.trino.gateway.proxyserver.ProxyResponseHandler       Header [Content-Length] = [[351]]

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required, with the following suggested text:

* Fix some things.

@Chaho12 Chaho12 self-assigned this Sep 10, 2025
@cla-bot cla-bot bot added the cla-signed label Sep 10, 2025
@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch 2 times, most recently from d4338a5 to 8e3975d Compare September 11, 2025 23:37
@Chaho12 Chaho12 marked this pull request as ready for review September 11, 2025 23:38
@Chaho12 Chaho12 changed the title Allow compression for response Add support for request and response compression Sep 11, 2025
@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch from 8e3975d to 3a7f15f Compare September 16, 2025 03:06
@Chaho12 Chaho12 requested a review from ebyhr September 16, 2025 08:11
@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch from 3a7f15f to 15c12e9 Compare September 16, 2025 23:44
@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch from 15c12e9 to fb2dc46 Compare September 17, 2025 01:00
@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch from fb2dc46 to 0f0a82d Compare September 19, 2025 01:33
@Chaho12 Chaho12 requested a review from ebyhr September 19, 2025 01:35
@oneonestar
Copy link
Member

Looks like Airlift disabled Jetty's GZIPContentDecoder using a hack.
If we can make this optional in Airlift, we can avoid doing the heavy lifting.
Also, using Jetty's decoder is better since there are many possible encoding (zstd, compress...) and we only handle gzip here.

Copy link
Member

@vishalya vishalya left a comment

Choose a reason for hiding this comment

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

Nice work! We should consider supporting encodings and compression methods that help optimize network bandwidth during communication. Have we evaluated the potential impact of this change on CPU performance? May be you can have some tests for it.

// Check if the response is gzip-compressed
String contentEncoding = headers.get(HeaderName.of("Content-Encoding")).stream().findFirst().orElse(null);

if ("gzip".equalsIgnoreCase(contentEncoding)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this the only encoding trino clients request? Then we should only allow that encoding here.
You can also test with Accept-Encoding: gzip, deflate
The spooling protocol offers additional encodings.

}

// Not compressed, convert bytes to string
return new String(body, UTF_8);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be great if we could deal with just bytes, but it could have some other side effects.

// OkHttp automatically adds "Accept-Encoding: gzip" when none is specified
assertThat(response.body().string()).isEqualTo("gzip");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could also add a test which breaks current gateway max limit and make sure it work with your change?

{
// Test that Accept-Encoding header is properly forwarded to backends
String url = "http://localhost:" + routerPort + healthCheckEndpoint + "?test-compression";
String expectedAcceptEncoding = "gzip, deflate, br";
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a test with just String expectedAcceptEncoding = "deflate, br";

@Chaho12
Copy link
Member Author

Chaho12 commented Nov 4, 2025

Have we evaluated the potential impact of this change on CPU performance? May be you can have some tests for it.

Is there a good way to test/measure the impact?

@vishalya
Copy link
Member

vishalya commented Nov 4, 2025

I would just run a few local JFR recordings to see how it compares.

@Chaho12 Chaho12 force-pushed the feature/jyoo/enable-compression branch from 96d2ab9 to ebf075d Compare November 12, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants