- 使用的是全局的 transport
transport: &http.Transport{
DialContext: proxy.DailContext,
Proxy: func(req *http.Request) (*url.URL, error) {
if proxyURL, ok := req.Context().Value(proxy.KeyProxyURL).(*url.URL); ok {
return proxyURL, nil
}
return nil, nil
},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
IdleConnTimeout: 15 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 10 * time.Second,
MaxIdleConnsPerHost: 3,
},}
- 每次 resp.Body 也 close 了
附上 pprof 图,
http://img.aladdinding.cn/202304030947153.png
集中在 bufio NewReader/Writer 是什么原因呢?
- goroutine 数量也没有暴增,数量稳定在 3000-4000 ,下面是 transport 代码
pconn.br = bufio.NewReaderSize(pconn, t.readBufferSize())
pconn.bw = bufio.NewWriterSize(persistConnWriter{pconn}, t.writeBufferSize())
go pconn.readLoop()
go pconn.writeLoop()
return pconn, nil