Skip to content

Commit b1f5785

Browse files
committed
improvements to the HTTP transports
1 parent c7e9be5 commit b1f5785

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

engine/sessions/http_clients.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ func NewClients(perHost int) (*Clients, error) {
4949
}
5050

5151
return &Clients{
52-
General: &http.Client{Transport: genTr, Timeout: 20 * time.Second},
52+
General: &http.Client{Transport: genTr, Timeout: 30 * time.Second},
5353
Probe: &http.Client{
5454
Transport: probTr,
5555
// for probes, prefer per-request context timeouts; keep a hard cap anyway
56-
Timeout: 8 * time.Second,
56+
Timeout: 12 * time.Second,
5757
},
5858
Crawl: &http.Client{
5959
Transport: crwlTr,
6060
// crawls can legitimately take longer. Use request contexts to bound if needed
61-
Timeout: 45 * time.Second,
61+
Timeout: 60 * time.Second,
6262
Jar: jar,
6363
},
6464
genTr: genTr,
@@ -70,15 +70,15 @@ func NewClients(perHost int) (*Clients, error) {
7070
func newGeneralTransport() *http.Transport {
7171
return &http.Transport{
7272
Proxy: http.ProxyFromEnvironment,
73-
DialContext: amassnet.NewDialContext(5 * time.Second),
73+
DialContext: amassnet.NewDialContext(8 * time.Second),
7474
ForceAttemptHTTP2: true,
7575
MaxIdleConns: 200,
7676
MaxIdleConnsPerHost: 20,
77-
MaxConnsPerHost: 100,
77+
MaxConnsPerHost: 64,
7878
IdleConnTimeout: 90 * time.Second,
79-
TLSHandshakeTimeout: 5 * time.Second,
80-
ExpectContinueTimeout: 4 * time.Second,
81-
ResponseHeaderTimeout: 8 * time.Second,
79+
TLSHandshakeTimeout: 8 * time.Second,
80+
ExpectContinueTimeout: 1 * time.Second,
81+
ResponseHeaderTimeout: 15 * time.Second,
8282
// prefer correct TLS verification for APIs
8383
TLSClientConfig: &tls.Config{
8484
MinVersion: tls.VersionTLS12,
@@ -90,40 +90,39 @@ func newGeneralTransport() *http.Transport {
9090
func newProbeTransport(perHost int) *http.Transport {
9191
return &http.Transport{
9292
Proxy: http.ProxyFromEnvironment,
93-
DialContext: amassnet.NewDialContext(2 * time.Second),
94-
ForceAttemptHTTP2: true,
93+
DialContext: amassnet.NewDialContext(5 * time.Second),
94+
ForceAttemptHTTP2: false,
9595
// keep this lower: probes spray across many hosts; idle pools become “memory”
96-
MaxIdleConns: 100,
96+
MaxIdleConns: 64,
9797
MaxIdleConnsPerHost: perHost,
9898
MaxConnsPerHost: perHost * 3,
99-
IdleConnTimeout: 5 * time.Second,
100-
TLSHandshakeTimeout: 3 * time.Second,
99+
IdleConnTimeout: 15 * time.Second,
100+
TLSHandshakeTimeout: 6 * time.Second,
101101
ExpectContinueTimeout: 0,
102-
ResponseHeaderTimeout: 4 * time.Second,
102+
ResponseHeaderTimeout: 8 * time.Second,
103103
// often you’ll hit junk certs during probing; keep verification on by default.
104104
// if you *must* allow insecure probing, fork a separate transport with InsecureSkipVerify=true
105105
// but be intentional about it
106106
TLSClientConfig: &tls.Config{
107107
MinVersion: tls.VersionTLS12,
108108
},
109-
DisableKeepAlives: true,
110109
DisableCompression: true, // avoid spending CPU on gzip for tiny probe responses
111110
}
112111
}
113112

114113
func newCrawlTransport() *http.Transport {
115114
return &http.Transport{
116115
Proxy: http.ProxyFromEnvironment,
117-
DialContext: amassnet.NewDialContext(6 * time.Second),
116+
DialContext: amassnet.NewDialContext(8 * time.Second),
118117
ForceAttemptHTTP2: true,
119118
// crawling usually hits same hosts repeatedly; keep-alives pay off
120-
MaxIdleConns: 512,
119+
MaxIdleConns: 256,
121120
MaxIdleConnsPerHost: 32,
122-
MaxConnsPerHost: 128,
121+
MaxConnsPerHost: 96,
123122
IdleConnTimeout: 120 * time.Second,
124-
TLSHandshakeTimeout: 6 * time.Second,
123+
TLSHandshakeTimeout: 8 * time.Second,
125124
ExpectContinueTimeout: 1 * time.Second,
126-
ResponseHeaderTimeout: 12 * time.Second,
125+
ResponseHeaderTimeout: 20 * time.Second,
127126
TLSClientConfig: &tls.Config{
128127
MinVersion: tls.VersionTLS12,
129128
},

internal/net/network.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ type DialContext func(ctx context.Context, network, addr string) (net.Conn, erro
8686

8787
// NewDialContext performs the dial using global variables (e.g. LocalAddr).
8888
func NewDialContext(timeout time.Duration) DialContext {
89-
d := &net.Dialer{Timeout: timeout}
89+
d := &net.Dialer{
90+
Timeout: timeout,
91+
KeepAlive: 30 * time.Second,
92+
}
9093

9194
return func(ctx context.Context, network, addr string) (net.Conn, error) {
9295
_, p, err := net.SplitHostPort(addr)

0 commit comments

Comments
 (0)