http - golang 中的默认 HTTP 拨号超时值

标签 http go

我正在运行一个 golang http 客户端来对服务器进行压力测试。有时我会收到错误消息“dial tcp 161.170.xx.xxx:80: operation timed out”。

我认为这是 HTTP 客户端超时。我正在考虑根据 https://stackoverflow.com/a/16895878/198497 增加超时值,但我想先找出 golang 中的默认超时值是多少。如果它取决于操作系统而不是语言,我如何在 Mac OS 中检查此值?

最佳答案

根据 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 设置超时.

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

关于http - golang 中的默认 HTTP 拨号超时值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19696448/

相关文章:

google-app-engine - Google App Engine 何时启动或停止实例?

go - 无法将 time.Now() 转换为字符串

spring - 从 Spring 应用程序对非 Spring 应用程序的 Http 调用

c - 如何解析来自基于 C 的 Web 服务器的 HTTP 请求

firebase - 如何发出 firestore REST API PATCH 请求?

go - 在 Go 中根据字符串选择正确的导入

javascript - 访问 angularjs 中的私有(private) $$state 变量

objective-c - 过多的 HTTP 重定向

java - 如何触发 java 应用程序(来自 Google GO/golang sub_process 的 java -jar <app name>

go - 如何通过 Stackdriver Logging 将错误记录到 Stackdriver Error Reporting