Skip to content

perf: ⚡ Pool idle upstream connections per host - #1571

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
evaline-ju:max-idle
Oct 29, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
evaline-ju:max-idle

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The forward proxy and TLS bridge set MaxIdleConns: 100 but not MaxIdleConnsPerHost, so Go's default of 2 applied and more than two concurrent callers to one upstream opened a fresh TCP+TLS per request. Set the field to 100 on both transports.

Tests assert the field directly: a behavioral test needs real dial latency to force overlap, which localhost httptest on a fast machine doesn't provide.

Assisted-By: Claude (Anthropic AI) [email protected]

Related issue(s)

Fixes #1546

Summary by CodeRabbit

  • Performance
    • Outbound connections to the same host can now remain idle for reuse in larger numbers, supporting more efficient handling of repeated requests.
    • Both forward proxy traffic and upstream TLS connections allow up to 100 idle connections per host.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c45e60be-47ca-42b0-aa0d-aec0e5aa687a
Commits

Reviewing files that changed from the base of the PR and between 7454925 and 1527d1b.

Files selected for processing: 4
  • core/listener/forwardproxy/maxidle_test.go
  • core/listener/forwardproxy/server.go
  • core/tlsbridge/upstream.go
  • core/tlsbridge/upstream_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The forward-proxy and TLS-bridge HTTP transports now set MaxIdleConnsPerHost to 100. New tests verify that each transport uses a limit of at least 100.

Changes: Per-host connection pools

Layer / File(s) Summary
Set and verify per-host limits
core/listener/forwardproxy/server.go, core/tlsbridge/upstream.go, core/listener/forwardproxy/maxidle_test.go, core/tlsbridge/upstream_test.go
Both transports set MaxIdleConnsPerHost to 100. Tests verify the configured limit for each transport.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Source audit for http.Transport literals (1554): This change updates two transport literals but does not add the proposed source audit.

Suggested reviewers: huang195

Merge Risk: Minimal · up to 1527d

The change raises the per-host idle connection limits; no merge-blocking risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Issue #1546 requires MaxIdleConnsPerHost: 100 for both upstream transports and an automated concurrency check that demonstrates approximately one connection per worker. The PR adds the field in `cor… Add a deterministic automated test for the issue's repeated-concurrency acceptance criterion. The test must exercise the upstream client against an HTTP/1.1 origin, count accepted connections, and assert that the count is approximately the …
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: pooling idle upstream connections per host. The performance prefix and emoji add minor noise but do not make the title unclear or misleading.
Out of Scope Changes check Passed The changed production code implements issue #1546 in the two named transports. The added tests verify the new transport configuration. No unrelated production behavior or unrelated files are identifi…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Out of Scope Changes check

Explanation

The changed production code implements issue #1546 in the two named transports. The added tests verify the new transport configuration. No unrelated production behavior or unrelated files are identified.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 4 files.

Full details: Linked Issues check

Explanation

Issue #1546 requires MaxIdleConnsPerHost: 100 for both upstream transports and an automated concurrency check that demonstrates approximately one connection per worker. The PR adds the field in core/listener/forwardproxy/server.go and core/tlsbridge/upstream.go. The new tests only inspect the configured field. They do not verify connection reuse under repeated concurrent requests.

Resolution

Add a deterministic automated test for the issue's repeated-concurrency acceptance criterion. The test must exercise the upstream client against an HTTP/1.1 origin, count accepted connections, and assert that the count is approximately the worker count. Keep the direct transport-field checks if useful.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sets MaxIdleConnsPerHost: 100 on both upstream transports so connection count follows caller count rather than request count on h1-only upstreams. Direct field assertions in the tests are the right call here — a behavioral test would need real dial latency to force overlap. One nit inline; otherwise clean.

// Sane Go defaults for everything except DialContext, which we
// customize when mTLS is on.
MaxIdleConns: 100,
MaxIdleConns: 100,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: With MaxIdleConnsPerHost: 100 but the global MaxIdleConns still at 100, a single busy host can hold the entire idle pool — fine while LiteLLM dominates, but if you ever want headroom for LiteLLM + Keycloak concurrently, the global cap is the one to raise.

@huang195
huang195 merged commit b6d42e4 into rossoctl:main Oct 29, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 29, 2026
mrsabath added a commit that referenced this pull request Oct 29, 2026
Brings in the commits that landed while this branch was in review — #1561
(reload in-flight pipelines), #1562 (forgeable headers), #1563 (token cache
scope key), #1564 (tlsbridge bind redaction), #1571 (max-idle) and the rest —
and resolves the one real conflict they create here.

ONE CONFLICT, in forwardproxy.serveOutbound, and both sides were needed:

  - main (#1561) introduced `pinned := s.OutboundPipeline.ForPctx(pctx)` so
    every capability probe for the rest of the handler answers for the
    pipeline the request actually ran on rather than whatever a mid-request
    reload left in the Holder, and switched ownEncoding's two probes onto it.
  - this branch had added stripForUpstream's third parameter, keepUpgrade, so
    a forwarded WebSocket keeps its normalized Connection/Upgrade pair.

Main's version dropped the third argument because it did not have one; taking
either side alone would have lost the other. Resolved as main's pinned probes
calling stripForUpstream(r, ownEncoding, forwardUpgrade).

Checked rather than assumed, since the last merge of this shape hid a
semantic conflict behind a green build: every stripForUpstream call site
passes three arguments (serveOutbound's, and resendIfAsked's
keepUpgrade=false), and the WebSocket relay makes no capability probe of its
own, so there is nothing in it that #1561's pinning should have moved — the
one later probe in the function, WritesResponseBody, is already on `pinned`.
#1562 touches extproc and auth, not the forward proxy's hop-by-hop handling,
so it does not meet this feature.

Everything else auto-merged, including all three of this branch's doc edits
(framework-architecture.md's two upgrade conditions, CLAUDE.md's and
session-api.md's 101-row semantics), each verified present afterwards.

core go test 73 ok (core/plugins and core/plugins/opa fail to build for lack
of a cgo toolchain here, as on unmodified main); the 17 upgrade tests and
both usage tests pass; reloader and the whole listener tree clean;
forwardproxy clean under -race -count=2; cmd/cortex ok; gofmt, go vet and
go mod tidy -diff clean on both touched modules.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@evaline-ju
evaline-ju deleted the max-idle branch November 3, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf: Upstream transports keep only 2 idle connections per host

2 participants