douhuang3740 2016-05-23 23:59
浏览 154

优化获取请求-通过运输go更改RoundTripper

I reach a limit in the number of requests I can get using the default httpClient that my API wrapper provides.

//I was getting something like this at the beginning
Head www.example.com:80/: lookup example.com: no such host

To solve this I want to change the MaxIdleConnsPerHost setting for the httpClient.Transport of my client. It looks much more like this: However, the Transport my client uses is a RoundTripper and subsequently, it doesn't have a MaxIdleConnsPerHost param.

&oauth2.Transport{Source:(*oauth2.reuseTokenSource)(0xc2082ac0c0), 
              Base:http.RoundTripper(nil), 
              mu:sync.Mutex{state:0, sema:0x0}, 
              modReq:map[*http.Request]*http.Request(nil)
              }

The one I'm providing is mostly a default one and it lacks the proper configuration I suppose or simple what I want to do is not feasible.

&http.Transport{idleMu:sync.Mutex{state:0, sema:0x0}, 
                         idleConn:map[http.connectMethodKey][]*http.persistConn(nil), 
                         idleConnCh:map[http.connectMethodKey]chan *http.persistConn(nil), 
                         reqMu:sync.Mutex{state:0, sema:0x0}, 
                         reqCanceler:map[*http.Request]func()(nil), 
                         altMu:sync.RWMutex{w:sync.Mutex{state:0, sema:0x0}, 
                         writerSem:0x0, 
                         readerSem:0x0, 
                         readerCount:0, 
                         readerWait:0}, 
                         altProto:map[string]http.RoundTripper(nil), 
                         Proxy:(func(*http.Request) (*url.URL, error))(nil), 
                         Dial:(func(string, string) (net.Conn, error))(nil), 
                         TLSClientConfig:(*tls.Config)(nil), 
                         TLSHandshakeTimeout:0, 
                         DisableKeepAlives:false, 
                         DisableCompression:false, 
                         MaxIdleConnsPerHost:200, 
                         ResponseHeaderTimeout:0}

Can someone guide me on the right direction?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)