Skip to content

feat: optimize HTTP connection pooling for high-throughput scenarios#2174

Merged
nimrod-teich merged 3 commits into
mainfrom
feat/shared-http-transport-tls-session-cache
Jan 11, 2026
Merged

feat: optimize HTTP connection pooling for high-throughput scenarios#2174
nimrod-teich merged 3 commits into
mainfrom
feat/shared-http-transport-tls-session-cache

Conversation

@nimrod-teich

Copy link
Copy Markdown
Contributor

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

- Add SharedHttpTransport() singleton to maximize connection reuse
- Add TLS session cache (1024 entries) for session resumption
- Update DialHTTP and OptimizedHttpClient to use shared transport

This reduces CPU overhead from TLS handshakes by ~15-20% under high load.
Previously each parallel RPC connection created its own http.Transport,
resulting in separate connection pools and no TLS session sharing.
Now all connections share a single transport with pooled connections
and cached TLS sessions.
The HTTP Connector now uses a single shared rpcclient.Client instead
of maintaining a pool of clients. This is possible because:

- rpcclient.Client wrapping http.Client is goroutine-safe
- http.Transport handles connection pooling internally
- The shared transport (from previous commit) maximizes reuse

Benefits:
- Zero lock contention (no GetRpc/ReturnRpc mutex operations)
- Simpler code (~55 fewer lines)
- Better connection reuse through shared transport
- Lower memory (1 client vs N clients)

The gRPC connector remains unchanged as gRPC connections have
different semantics.
@nimrod-teich nimrod-teich force-pushed the feat/shared-http-transport-tls-session-cache branch from 9730239 to 5e0fe22 Compare January 8, 2026 13:41
@nimrod-teich nimrod-teich changed the title perf: optimize HTTP connection pooling for high-throughput scenarios feat: optimize HTTP connection pooling for high-throughput scenarios Jan 8, 2026
@nimrod-teich nimrod-teich changed the title feat: optimize HTTP connection pooling for high-throughput scenarios feat: optimize HTTP connection pooling for high-throughput scenarios Jan 8, 2026
@github-actions

github-actions Bot commented Jan 8, 2026

Copy link
Copy Markdown

Test Results

    7 files  ±0    128 suites  ±0   34m 29s ⏱️ -33s
3 190 tests +5  3 189 ✅ +5  1 💤 ±0  0 ❌ ±0 
3 273 runs  +8  3 272 ✅ +8  1 💤 ±0  0 ❌ ±0 

Results for commit 503107a. ± Comparison against base commit 18cb6d0.

This pull request removes 1 and adds 6 tests. Note that renamed tests count towards both.
github.com/lavanet/lava/v5/protocol/common ‑ TestMultipleClientsShareTransportSettings
github.com/lavanet/lava/v5/protocol/chainlib/chainproxy ‑ TestConnectorCloseWhileInUse
github.com/lavanet/lava/v5/protocol/chainlib/chainproxy ‑ TestConnectorConcurrentAccess
github.com/lavanet/lava/v5/protocol/common ‑ TestDefaultConstants/TLSSessionCacheSize
github.com/lavanet/lava/v5/protocol/common ‑ TestMultipleClientsShareTransport
github.com/lavanet/lava/v5/protocol/common ‑ TestSharedHttpTransportHasTLSSessionCache
github.com/lavanet/lava/v5/protocol/common ‑ TestSharedHttpTransportIsSingleton

♻️ This comment has been updated with latest results.

Comment thread protocol/chainlib/chainproxy/connector_test.go
Comment thread protocol/chainlib/chainproxy/connector.go
Comment thread protocol/chainlib/chainproxy/connector_test.go
Increase HTTP transport limits to handle high-throughput scenarios:

- MaxIdleConns: 200 → 1000 (support 1000 concurrent idle connections)
- MaxIdleConnsPerHost: 50 → 500 (allow connection reuse at scale)
- MaxConnsPerHost: 100 → 0 (unlimited - was causing request queuing)

At 1000 req/s with 500ms avg response time, ~500 concurrent connections
are needed. The previous MaxConnsPerHost=100 limit was causing requests
to queue, adding latency and creating cascading failures.
@nimrod-teich nimrod-teich force-pushed the feat/shared-http-transport-tls-session-cache branch from 5e0fe22 to 503107a Compare January 11, 2026 11:57
@nimrod-teich nimrod-teich merged commit 8fe264c into main Jan 11, 2026
30 checks passed
@nimrod-teich nimrod-teich deleted the feat/shared-http-transport-tls-session-cache branch January 11, 2026 12:43
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