小编Nev*_*olt的帖子

在同时请求时拨打 tcp I/O 超时

我正在用 Go 构建一个工具,它需要向许多不同的服务器发出大量并发 HTTP 请求。我在 Python 中的初始原型在处理几百个并发请求时没有问题。

但是,我发现在 Go 中Get http://www.google.com: dial tcp 216.58.205.228:80: i/o timeout,如果同时请求的数量超过 ~30-40,这几乎总是会导致某些情况。

我已经在 macOS、openSUSE、不同的硬件、不同的网络和不同的域列表上进行了测试,并且按照其他 Stackoverflow 答案中的描述更改 DNS 服务器也不起作用。

有趣的是,失败的请求甚至不会产生数据包,这在使用 Wireshark 进行检查时可以看出。

有什么我做错了还是 Go 中的错误?

最低可重现程序如下:

package main

import (
    "fmt"
    "net/http"
    "sync"
)

func main() {
    domains := []string{/* large domain list here, eg from https://moz.com/top500 */}

    limiter := make(chan string, 50) // Limits simultaneous requests

    wg := sync.WaitGroup{} // Needed to not prematurely exit before all requests have been finished

    for i, …
Run Code Online (Sandbox Code Playgroud)

network-programming http go go-http

9
推荐指数
1
解决办法
9331
查看次数

标签 统计

go ×1

go-http ×1

http ×1

network-programming ×1