对同一台 PC 上的多个进程的 UDP 广播性能较差
我们有一个应用程序,它使用 UDP 将数据从服务器系统广播到多台 Windows XP PC 上运行的客户端应用程序。这是在 LAN 上,通常是千兆位。这几年来一直运行良好。
现在,我们需要在每台四核 PC 上运行两个(或更多)客户端应用程序,每个应用程序实例都接收广播数据。我用来实现此目的的方法是为每个客户端 PC 提供多个 IP 地址。然后,每个客户端应用程序使用相同的端口号但在不同的 IP 上连接到服务器。这可以正常工作,但由于某种原因性能非常差。我的数据传输率降低了大约 10 倍!
为了获取多个 IP 地址,我尝试了使用两个 NIC 适配器并在高级 TCP/IP 网络属性中将多个 IP 地址分配给单个 NIC。这两种方法似乎都表现出同样糟糕的性能。我还尝试使用几个不同制造商的网卡,但这也没有帮助。
我确实注意到的一件事是,数据似乎更加分散。在 PC 上只有一个客户端的情况下,如果我向客户端发送 20kByte 的数据,它几乎总是会在一个块中接收到所有数据。但是,当两个客户端运行时,数据似乎主要以帧大小(1500 字节)的块形式传输,因此我的代码必须迭代更多次。但我不认为这本身会造成如此戏剧性的性能打击。
所以我想我的问题是有人知道为什么性能这么慢以及是否可以采取任何措施来加快速度?
我知道我可以重新设计,以便服务器仅将数据发送到每台 PC 的一个客户端,然后该客户端可以将数据镜像到同一台 PC 上的其他客户端。但这是一项重大的重新设计和重新编码工作,因此我想将其作为最后的手段。
We have an application that broadcasts data using UDP from a server system to client applications running on multiple Windows XP PC's. This is on a LAN, typically Gigabit. This has been running fine for some years.
We now have a requirement to have two (or more) of the client applications running on each quad core PC, with each instance of the application receiving the broadcast data. The method I have used to implement this is to give each client PC multiple IP addresses. Each client app then connects to the server using the same port number but on a different IP. This works functionally but the performance for some reason is very poor. My data transfer rate is cut by around a factor of 10!
To get multiple IP addresses I have tried both using two NIC adapters and assigning multiple IP addresses to a single NIC in the advanced TCP/IP network properties. Both methods seem to give similarly poor performance. I also tried using several different manufacturers NICs but that didn't help either.
One thing I did notice is that the data seems to come over more fragmented. With just a single client on a PC if I send 20kBytes of data to the client it almost always receives it all in one chunk. But with two clients running the data seems to mostly come over in blocks the size of a frame (1500 bytes) so my code has to iterate around more times. But I wouldn't expect this on its own to cause such a dramatic performance hit.
So I guess my question is does any one know why the performance is so much slower and if anything can be done to speed it up?
I know I could re-design things so that the server only sends data to one client per PC, and that client could then mirror the data on to the other clients on the same PC. But that is a major redesign and re-coding effort so I'd like to keep that as a last resort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要为每个客户端创建一个IP 地址,而是尝试使用setsockopt() 为每个套接字启用SO_REUSEADDR 选项。这将允许所有客户端绑定到同一主机地址上的同一端口并接收广播数据。应该比多 NIC/IP 地址方法更容易管理。
SO_REUSEADDR 将允许广播和多播套接字共享相同的端口和地址。欲了解更多信息,请参阅:
Windows 中的 SO_REUSEADDR 和 UDP 行为
和
SO_REUSEADDR 的用途?
Instead of creating one IP address for each client, try using setsockopt() to enable the SO_REUSEADDR option for each of your sockets. This will allow all of your clients to bind to the same port on the same host address and receive the broadcast data. Should be easier to manage than the multiple NIC/IP address approach.
SO_REUSEADDR will allow broadcast and multicast sockets to share the same port and address. For more info see:
SO_REUSEADDR and UDP behavior in Windows
and
Uses of SO_REUSEADDR?