防止TCP连接造成UDP丢包 [英] Prevent TCP connections from causing UDP packet loss

查看:79
本文介绍了防止TCP连接造成UDP丢包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑原型多人游戏服务器.

Consider the prototypical multiplayer game server.

允许连接到服务器的客户端下载地图和脚本.创建 TCP 连接来完成此操作非常简单.

Clients connecting to the server are allowed to download maps and scripts. It is straightforward to create a TCP connection to accomplish this.

但是,服务器必须继续通过 UDP 响应其余客户端.如果允许 TCP 下载连接使可用带宽饱和,则 UDP 流量将严重遭受数据包丢失的影响.

However, the server must continue to be responsive to the rest of the clients via UDP. If TCP download connections are allowed to saturate available bandwidth, UDP traffic will suffer severely from packet loss.

处理这个问题的最佳方法是什么?通过跟踪时间和 send() 在固定的时间间隔内以某种方式限制"TCP 上传连接,这绝对是一个好主意.这样,如果 UDP 数据包丢失开始更频繁地发生,则 TCP 连接可能会进一步受到限制.操作系统是否仍然倾向于将数据集中在一起而不是稳定地发送数据?我希望多久调用一次 send()?我想这样做太频繁会导致数据首先被缓冲在一起,从而使方法无效,而太少这样做会导致带宽不足(并且使用效率低下).关于每次发送多少数据也存在类似的考虑.

What might be the best way to deal with this issue? It definitely seems like a good idea to "throttle" the TCP upload connection somehow by keeping track of time, and send() on a regular time interval. This way, if UDP packet loss starts to occur more frequently the TCP connections may be throttled further. Will the OS tend to still bunch the data together rather than sending it off in a steady stream? How often would I want to be calling send()? I imagine doing it too often would cause the data to be buffered together first rendering the method ineffective, and doing it too infrequently would provide insufficient (and inefficient use of) bandwidth. Similar considerations exist with regard to how much data to send each time.

推荐答案

这听起来很像是你在用错误的方式解决问题:

It sounds a lot like you're solving a problem the wrong way:

  1. 如果您担心丢失 UDP 数据包,则应考虑不使用 UDP.
  2. 如果您担心在两个函数之间共享带宽,您应该考虑为它们设置单独的管道(带宽).
  3. 流量整形(这听起来像)通常在操作系统中解决.在对应用程序进行奇怪的更改之前,您应该朝那个方向看.
  4. 如果您还没有使应用程序运行并遇到此问题,则您可能过早地进行了优化.

这篇关于防止TCP连接造成UDP丢包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆