27 lines
826 B
Go
27 lines
826 B
Go
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}
|
|
}
|