golang中的默认HTTP拨号超时值 [英] Default HTTP dial timeout value in golang

查看:123
本文介绍了golang中的默认HTTP拨号超时值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个golang http客户端来压力测试服务器。有时我得到错误拨号tcp 161.170.xx.xxx:80:操作超时错误。我认为这是一个HTTP客户端超时。我正在考虑增加基于 https://stackoverflow.com/a/16895878/198497 的超时值,但我想要先了解golang的默认超时值是什么。如果它取决于os而不是语言,我该如何在Mac OS上检查这个值?

=http://golang.org/pkg/net/#Dialer =noreferrer> http://golang.org/pkg/net/#Dialer

 类型拨号结构{
//超时是拨号等待
// a连接完成的最长时间。如果Deadline也被设置,它可能会在
//之前失败。
//
//默认没有超时。
//
//有或没有超时时,操作系统可能会强制
//自己的较早超时。例如,TCP超时通常是3分钟左右
//。

所以默认的超时,没有考虑到操作系统强加的限制是没有的。



超时时间可以通过 SetDeadline



使用 sysctl net.inet可以检查默认的OSX超时时间(我认为)。 tcp


I am running a golang http client to stress test a server. Sometimes I got error "dial tcp 161.170.xx.xxx:80: operation timed out" error.

I think this is a HTTP client timeout. I am thinking about increase the timeout value based on https://stackoverflow.com/a/16895878/198497, but I would like to find out what's the default timeout value in golang first. If it is depends on os instead of language, how can I check this value in Mac OS?

解决方案

According to http://golang.org/pkg/net/#Dialer :

type Dialer struct {
        // Timeout is the maximum amount of time a dial will wait for
        // a connect to complete. If Deadline is also set, it may fail
        // earlier.
        //
        // The default is no timeout.
        //
        // With or without a timeout, the operating system may impose
        // its own earlier timeout. For instance, TCP timeouts are
        // often around 3 minutes.

So the default timeout, without taking into account OS imposed limits is none.

The timeout can be set with SetDeadline.

The default OSX timeout can (I think) be checked with sysctl net.inet.tcp.

这篇关于golang中的默认HTTP拨号超时值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆