从 net.UDPConn 读取会导致计算机死机。

huangapple go评论90阅读模式
英文:

Reading from net.UDPConn locks up PC

问题

作为一个测试,我写了一个小工具来测试两台计算机之间的局域网连接。它是一个客户端/服务器模型,只是尽可能发送尽可能多的UDP数据包,然后在另一端我尽可能读取所有数据。

为了充分利用我的资源,我为我的机器的每个核心启动了一个goroutine。

发送、接收和测量速度都正常,但当我达到高吞吐量(500+ Mb/s)时,接收端变得完全无响应。

如果我限制连接速度,就没有任何问题。

此外,我的CPU只使用了一个核心的最大资源(尽管我使用了runtime.GOMAXPROCS(0)并在runtime.NumCPU个goroutine中开始接收)。

我将代码上传到了GitHub上,链接在这里:https://github.com/femot/lanbench

如果我将客户端更改为在本地运行,问题就不会发生。只有当我从另一台计算机启动客户端时才会出现这个问题(尽管测得的速度也只能达到650 Mb/s)。

英文:

As a test I wrote little tool to test the LAN connection between two PCs.
It is a client/server model that just sends as many UDP packets as it can and on the other side I read everything I can.
To max out my resources, I start a goroutine for every core my machine has.
Sending, receiving and measuring speed works, but when I get to high throughput (500+ Mb/s), the receiving end becomes completely unresponsive.
If I throttle the connection, I don't have any problems.
Also my CPU maxes out just one core (although i used runtime.GOMAXPROCS(0) and start to receive in runtime.NumCPU goroutines)

从 net.UDPConn 读取会导致计算机死机。

I uploaded the code to GitHub over here: https://github.com/femot/lanbench

If I change the client to run locally, the problem does not occur. It only happens, if I start the client from another PC (although the measured speed also tops out at 650 Mb/s)

答案1

得分: 1

您的服务器首先受到具有100个缓冲区的增量通道的限制。我确信在任何显著的数据包速率下,您都会超过该循环的负载。

这不是一个很好的基准测试,因为数据包速率将是一个更为限制的因素,而不仅仅是带宽。您只是试图测试Go语言发送和接收1024字节UDP数据报的速度。

无论您启动多少个goroutine,所有的IO都会通过网络轮询器在单个线程中进行。如果您无法用单个核心饱和您的链接,您将需要多个进程或者需要使用另一种语言来完成这个任务。

英文:

Your server is limited first by the delta channel with a buffer of 100. I'm sure at any significant packet rate that you will be overwhelming that loop.

This isn't a very good benchmark, since your packet rate is going to be a limiting factor more so than bandwidth. You're specifically only trying to test how fast Go can send and receive 1024byte UDP datagrams.

Regardless of how many goroutines you start, the IO is all going through the network poller in a single thread. If you can't saturate your link with a single core, you're going to need multiple process or you need to do this in another language.

huangapple
  • 本文由 发表于 2015年12月16日 00:46:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/34294817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定