2013-10-31 18 views
3

我正在运行golang http客户端来压力测试服务器。有时我得到错误“拨号tcp 161.170.xx.xxx:80:操作超时”错误。golang中的默认HTTP拨号超时值

我认为这是一个HTTP客户端超时。我正在考虑根据https://stackoverflow.com/a/16895878/198497增加超时值,但我想先了解一下golang的默认超时值。如果它取决于os而不是语言,我如何在Mac OS中检查这个值?

回答

7

根据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. 

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

超时时间可以使用SetDeadline进行设置。

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