Skip to content

perf(router): skip upstream gzip auto-decode on smart-router HTTP req…#2272

Merged
nimrod-teich merged 1 commit intomainfrom
perf/disable-upstream-gzip-decode
Apr 16, 2026
Merged

perf(router): skip upstream gzip auto-decode on smart-router HTTP req…#2272
nimrod-teich merged 1 commit intomainfrom
perf/disable-upstream-gzip-decode

Conversation

@NadavLevi
Copy link
Copy Markdown
Collaborator

…uests

Go's default http.Transport auto-adds Accept-Encoding: gzip on outbound requests when no Accept-Encoding is set, and transparently decodes responses via net/http.(*http2gzipReader).Read → compress/gzip.Reader → compress/flate. Production pprof on the eth router attributed ~30-39% of total CPU to that inflate chain — CPU we spend decoding bytes we then either pass through, re-encode with gzip for the client, cache as a blob, or peek at with CheckResponseError.

Two coordinated changes remove that work only on the smart router:

  1. Switch lavasession.HTTPDirectRPCConnection from its own fresh &http.Client{} (default transport — no pooling, no TLS session cache, no HTTP/2) to common.OptimizedHttpClient(). Every smart-router HTTP connection now shares common.SharedHttpTransport() and inherits connection pooling, TLS session resumption, and ForceAttemptHTTP2.

  2. Set Accept-Encoding: identity on every outbound request from HTTPDirectRPCConnection.SendRequest and DoHTTPRequest. Go only auto-adds gzip when the caller left Accept-Encoding empty; once identity is set, both the auto-add and auto-decode are skipped.

The scoping matters: the shared transport keeps its default compression behavior, so provider chain proxies (chainlib/rest.go, tendermintRPC.go, chainproxy/rpcclient/http.go) continue to auto-gzip as before. The opt-out lives exclusively on the smart-router request path.

Measured impact on the eth router (same 900s pprof window, back-to-back before/after the deploy):

CPU cores (avg): 2.47 → 1.23 (-50%)
Memory inuse: 277 GB → 186 GB (-33%)
Gzip-decode CPU path: 38.9% → 0% (eliminated from the top 25)
RelayCacheSet.Marshal: 30 GB → 19 GB (-37%)

Tradeoff: upstream bandwidth goes up because nodes now send plain JSON on the wire for smart-router traffic. For co-located upstreams this is free; geographically-distant deployments trade CPU for bytes. Per-request deadlines are unchanged (caller context via NewRequestWithContext); the client's 5-minute DefaultHTTPTimeout is a safety backstop above any realistic upstream timeout.

Covered by:

  • TestHTTPDirectRPCConnection_UsesSharedOptimizedTransport: regression lock-in that two HTTPDirectRPCConnection instances share the singleton common.SharedHttpTransport() for pooling and TLS session reuse.
  • TestHTTPDirectRPCConnection_AdvertisesAcceptEncodingIdentity: httptest end-to-end assertion that both SendRequest and DoHTTPRequest send Accept-Encoding: identity on outbound requests and that response bodies are returned untransformed.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
consensus 8.98% <ø> (ø)
protocol 35.25% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/lavasession/direct_rpc_connection.go 32.29% <100.00%> (+4.65%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

Test Results

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
7 files   ±0   0 ❌ ±0 

Results for commit 71eeb95. ± Comparison against base commit 2d92617.

♻️ This comment has been updated with latest results.

@NadavLevi NadavLevi force-pushed the perf/disable-upstream-gzip-decode branch from be47970 to 8a4228d Compare April 15, 2026 05:54
Comment thread protocol/lavasession/direct_rpc_connection_test.go
@NadavLevi NadavLevi requested a review from avitenzer April 15, 2026 17:08
@NadavLevi NadavLevi force-pushed the perf/disable-upstream-gzip-decode branch from 8a4228d to b22374a Compare April 15, 2026 17:08
…uests

Go's default http.Transport auto-adds `Accept-Encoding: gzip` on outbound
requests when no Accept-Encoding is set, and transparently decodes responses
via net/http.(*http2gzipReader).Read → compress/gzip.Reader → compress/flate.
Production pprof on the eth router attributed ~30-39% of total CPU to that
inflate chain — CPU we spend decoding bytes we then either pass through,
re-encode with gzip for the client, cache as a blob, or peek at with
CheckResponseError.

Two coordinated changes remove that work *only on the smart router*:

  1. Switch lavasession.HTTPDirectRPCConnection from its own fresh
     &http.Client{} (default transport — no pooling, no TLS session cache,
     no HTTP/2) to common.OptimizedHttpClient(). Every smart-router HTTP
     connection now shares common.SharedHttpTransport() and inherits
     connection pooling, TLS session resumption, and ForceAttemptHTTP2.

  2. Set `Accept-Encoding: identity` on every outbound request from
     HTTPDirectRPCConnection.SendRequest and DoHTTPRequest. Go only
     auto-adds `gzip` when the caller left Accept-Encoding empty; once
     identity is set, both the auto-add and auto-decode are skipped.

The scoping matters: the shared transport keeps its default compression
behavior, so provider chain proxies (chainlib/rest.go, tendermintRPC.go,
chainproxy/rpcclient/http.go) continue to auto-gzip as before. The opt-out
lives exclusively on the smart-router request path.

Measured impact on the eth router (same 900s pprof window, back-to-back
before/after the deploy):

  CPU cores (avg):       2.47 → 1.23    (-50%)
  Memory inuse:          277 GB → 186 GB (-33%)
  Gzip-decode CPU path:  38.9% → 0% (eliminated from the top 25)
  RelayCacheSet.Marshal: 30 GB → 19 GB  (-37%)

Tradeoff: upstream bandwidth goes up because nodes now send plain JSON on
the wire for smart-router traffic. For co-located upstreams this is free;
geographically-distant deployments trade CPU for bytes. Per-request
deadlines are unchanged (caller context via NewRequestWithContext); the
client's 5-minute DefaultHTTPTimeout is a safety backstop above any
realistic upstream timeout.

Covered by:
  - TestHTTPDirectRPCConnection_UsesSharedOptimizedTransport: regression
    lock-in that two HTTPDirectRPCConnection instances share the singleton
    common.SharedHttpTransport() for pooling and TLS session reuse.
  - TestHTTPDirectRPCConnection_AdvertisesAcceptEncodingIdentity: httptest
    end-to-end assertion that both SendRequest and DoHTTPRequest send
    Accept-Encoding: identity on outbound requests and that response
    bodies are returned untransformed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@NadavLevi NadavLevi force-pushed the perf/disable-upstream-gzip-decode branch from b22374a to 71eeb95 Compare April 15, 2026 17:14
@nimrod-teich nimrod-teich merged commit 3f1baeb into main Apr 16, 2026
30 checks passed
@nimrod-teich nimrod-teich deleted the perf/disable-upstream-gzip-decode branch April 16, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants