MacOS:UDP/TCP 数据包之间出现奇怪的延迟
我正在开发一个应用程序,它使用 AsyncUDPSocket 类将每个 UDP 数据发送到 Mac 和 Windows 上的另一个客户端。数据包立即到达非常重要。
问题是每大约。 1000 个数据包时,我在接收数据包时延迟了大约 2 秒。 100-200 毫秒的延迟还可以,但 2 秒就会产生糟糕的用户体验。
我在单独的线程中进行 UDP 通信,因此它几乎不受用户与 UI 交互等的影响。我已经尝试过更快、更慢、不同大小的数据包发送:延迟仍然存在。尝试使用 TCP 而不是 UDP - 相同的结果:(
Windows Client 上似乎不会发生这种情况。 也许MacOS中有一些系统缓冲区,每次有N个数据包或N个字节的数据时都需要刷新??? 有谁知道如何防止延迟发生?
I am developing an application that sends data per UDP using AsyncUDPSocket class to another client on Mac and Windows. It is very important that packets arrive instantly.
The problem is that every approx. 1000 packets I get a delay for about 2 seconds when receiving Packets. A delay of 100-200 ms would be OK, but 2 seconds produce bad user experience.
I have the UDP communication in a separate Thread, so it is little affected by user interaction with UI and such. I have already tried sending Packets faster, slower, different Packet sizes: the delay stays there. Tried using TCP instead of UDP - same result :(
It does not seem to happen on Windows Cliets.
Maybe there is some system buffer in MacOS that needs to be flushed every time it hast N packets or N bytes of data???
Has anyone an idea how can I prevent the delay from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多因素会暂时减慢网络程序的速度,但很难知道从哪里开始。您是否在多个网络上尝试过此操作?无线网络和以太网网络?你有什么样的开关?这种情况是发生在不同的 OS X 计算机上,还是仅发生在一台计算机上?您可以使用更简单的命令行程序重现延迟吗?您正在使用垃圾收集吗? (抓住这里的救命稻草......)
出于好奇,我测试了从我的 Mac 发送到同一 LAN 上另一台计算机的 UDP 回显数据包的往返时间。在超过 60,000 个 1,000 字节有效负载的 UDP 数据包中,没有一个数据包花费的时间超过 32 毫秒,平均往返时间为 0.6 毫秒,样本偏差为 0.21。
(我也很好奇你需要这么低的延迟做什么。)
There are a lot of things that can slow down a network program temporarily, it's hard to know where to start. Have you tried this on multiple networks? Both wireless and ethernet networks? What kind of switch do you have? Does this happen on different OS X computers, or just on one? Can you reproduce the delay with a simpler command line program? Are you using garbage collection? (Grasping at straws here...)
Just out of curiosity, I tested the roundtrip time on UDP echo packets sent from my Mac to another computer on the same LAN. Out of over 60,000 UDP packets with a 1,000 byte payload, none of them took longer than 32 ms, the mean round trip was 0.6 ms, and the sample deviation was 0.21.
(I'm also curious what you need such low latency for.)