perf: Upstream transports keep only 2 idle connections per host
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- backend, networking
Hướng nghiên cứu
Đọc core/tlsbridge/upstream.go và core/listener/forwardproxy/server.go tại các thiết lập truyền tải được nêu trong issue. Thêm thiết lập pool kết nối đi kèm vào cả hai nơi, sau đó chạy lặp lại thử nghiệm TestUpstreamPoolReuse được cung cấp từ core/tlsbridge/. Hoàn tất khi mỗi worker mở khoảng một kết nối upstream, thay vì nhiều lần con số đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
The proxy keeps only 2 idle upstream connections per host. When more than two requests to one host overlap, each extra request opens a new TCP+TLS connection rather than reusing one, and that connection is closed afterwards instead of being kept for the next request.
This hurts most on a gateway that speaks only HTTP/1.1, where each connection carries one request at a time. LiteLLM is one: it offers no h2 in ALPN. Each extra handshake costs about 40-90 ms on the laptop's VPN-reached gateways.
Reproduction
The bridge's own upstream client (tlsbridge.NewUpstreamClient), callers running at the same time, 10 sequential requests each, against one h1-only TLS origin. We counted the TCP connections the origin accepted, over three runs:
| Concurrent callers | Ideal | Today | With MaxIdleConnsPerHost: 100 |
|---|---|---|---|
| 4 | 4 | 5 / 16 / 19 | 5 / 5 / 5 |
| 10 | 10 | 36 / 39 / 45 | 18 / 19 / 23 |
| 20 | 20 | 66 / 76 / 79 | 46 / 49 / 49 |
Through the forward proxy end to end (10 bridged clients × 10 requests), the origin accepted 69 connections.
Test source (drop into core/tlsbridge/)
package tlsbridge
import (
"crypto/tls"
"io"
"net"
"net/http"
"net/http/httptest"
"sync"
"sync/atomic"
"testing"
)
func TestUpstreamPoolReuse(t *testing.T) {
var conns atomic.Int32
origin := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { io.WriteString(w, "ok") }))
origin.Config.ConnState = func(_ net.Conn, s http.ConnState) {
if s == http.StateNew {
conns.Add(1)
}
}
origin.TLS = &tls.Config{NextProtos: []string{"http/1.1"}} // h1-only, like LiteLLM
origin.StartTLS()
defer origin.Close()
const workers = 10
c, _ := NewUpstreamClient(nil, true)
var wg sync.WaitGroup
for i := 0; i < workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < 10; j++ {
if resp, err := c.Get(origin.URL); err == nil {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
}
}()
}
wg.Wait()
t.Logf("%d callers x 10 requests: %d upstream connections (ideal %d)", workers, conns.Load(), workers)
}
Why
Both transports set MaxIdleConns: 100 (the total across all hosts) but not MaxIdleConnsPerHost, so Go's DefaultMaxIdleConnsPerHost of 2 applies:
core/tlsbridge/upstream.go:31: every decrypted (bridged) request goes through this transport.core/listener/forwardproxy/server.go:212: plain-HTTP forward-proxy requests.
Possible fix
Add MaxIdleConnsPerHost: 100 next to MaxIdleConns in both transports. Two lines.
Even with the fix, concurrent callers still open more connections than the ideal; Go dials a new connection whenever none is idle at that moment. A MaxConnsPerHost cap would bound that too, but it makes extra requests wait in a queue, so it is a separate decision.
Acceptance
The test above opens about workers connections, not several times that, across repeated runs.
Related, not verified
proxy.log on a laptop shows 65 fast EOF failures (128-221 ms) on LiteLLM POSTs. That is the usual sign of reusing a connection the server had just closed. Go retries such a request only when it can replay the body, and the forward proxy never sets r.GetBody after buffering the body (setBody, server.go:1306). We did not reproduce this, so it is noted here rather than filed.
Found by an experiment-driven audit of main at 43cf5539; every number above was re-measured on that commit.
Assisted-By: Claude (Anthropic AI) [email protected]
- Ngôn ngữ chính
- Go
- Star
- 21
- Fork
- 43
- Merge trung bình
- 14 giờ 25 phút
- Pull request đã merge (30 ngày)
- 245
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rossoctl/cortex
-
aiac enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
UI shows costs for all sessions even when drilled into a sessionCó thể đã có người làm @esnible đã nhận 16 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
rossoctl/cortex#1116 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug laptop
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: Copied listener and parser code has drifted (hop-by-hop response headers, SSE BOM/CR handling)Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: Ring and ledger count errors and coverage differently, cost reads slow down over time, and cost comments are staleCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 49/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rossoctl/cortex
Issue tương tự
-
feat(gmail): make gmail get --format raw text output the exact message, like drafts get --format rawĐang mởclawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openclaw/gogcli#1276 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
coder/chat#151 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
hiero-ledger/hiero-sdk-go#1886 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cloudevents/sdk-go#1346 ·