perf(cmpp): isolate inbound transport capacity

This commit is contained in:
hectorzhao
2026-08-20 18:09:29 +08:00
parent 53073461e9
commit 6708f1f7c5
11 changed files with 95 additions and 8 deletions
+26
View File
@@ -0,0 +1,26 @@
package inbound
import (
"net"
"net/http"
"time"
)
// NewAPIHTTPClient keeps enough loopback connections warm for the bounded CMPP
// Submit window. Go's default of two idle connections per host otherwise causes
// connection churn exactly when SubmitResp latency matters most.
func NewAPIHTTPClient(maxConcurrency int) *http.Client {
if maxConcurrency < 1 {
maxConcurrency = 64
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.MaxIdleConns = maxConcurrency + 16
transport.MaxIdleConnsPerHost = maxConcurrency
transport.MaxConnsPerHost = maxConcurrency
transport.IdleConnTimeout = 90 * time.Second
transport.DialContext = (&net.Dialer{
Timeout: 3 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext
return &http.Client{Transport: transport, Timeout: defaultHTTPTimeout}
}