英文:
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)
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论