How to get DNS lookup time from Dialer.Dial ?

blov · · 1239 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am using Dialer.Dial from package net to make a tcp connection. Currently i can measure the time it takes to make the connection like so :-</p> <pre><code>start := time.Now() dialer := &amp;net.Dialer{ } con, err := dialer.Dial(&#34;tcp&#34;, &#34;example.com:80&#34;) log.Println(&#34;dial time: &#34;, time.since(start)) </code></pre> <p>This gives me the total time to establish the connection which includes DNS and tcp connect. I would like to know the DNS lookup time and connect time separately...</p> <p>So far the options I see are...</p> <ol> <li>Resolve the hostname by hand, and feed one of the ip into Dial - but here I loose fallback and dualstack strategy provided inside Dialer.Dial</li> <li>Recreate the whole logic in my code - But this is too much work and I am lazy. Reproducing things from standard library sounds like not a good thing.</li> </ol> <p>The first thing <a href="https://golang.org/src/net/dial.go?s=6061:6121#L197">Dialer.Dial</a> does is :-</p> <pre><code>addrs, err := resolveAddrList(&#34;dial&#34;, network, address, finalDeadline) </code></pre> <p>Is there a way to either time that step? Or be able to provide a list of addrs to Dial instead of single hostname/IP?</p> <p>Looking for an easier way out.</p> <p>PS: My code where I need to implement inside <a href="https://github.com/turbobytes/pulse/blob/master/utils/curl.go#L77">func dial</a></p> <hr/>**评论:**<br/><br/>bradfitz: <pre><p>File a feature request bug.</p></pre>sajal: <pre><p>Thanks. Done <a href="https://github.com/golang/go/issues/12476" rel="nofollow">https://github.com/golang/go/issues/12476</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1239 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传