问题描述
通过 UDP 发送大量小数据包会占用更多资源(cpu、zlib 压缩等).我在这里读到,通过 UDP 发送一个约 65kBYTE 的大数据包可能会失败所以我认为发送大量较小的数据包会更频繁地成功,但随之而来的是使用更多处理能力的计算开销(或者至少这是我假设的).问题基本上是这样的;发送最大成功数据包并将计算降至最低的最佳方案是什么?是否有在大多数情况下都有效的特定尺寸?我将 Erlang 用于服务器,将 Enet 用于客户端(用 C++ 编写).也使用 Zlib 压缩,我向每个客户端发送相同的数据包(我猜是广播这个术语).
Would sending lots a small packets by UDP take more resources (cpu, compression by zlib, etc...). I read here that sending one big packet of ~65kBYTEs by UDP would probably fail so I'm thought that sending lots of smaller packets would succeed more often, but then comes the computational overhead of using more processing power (or at least thats what I'm assuming). The question is basically this; what is the best scenario for sending the maximum successful packets and keeping computation down to a minimum? Is there a specific size that works most of the time? I'm using Erlang for a server and Enet for the client (written in c++). Using Zlib compression also and I send the same packets to every client (broadcasting is the term I guess).
推荐答案
UDP payload
在大多数情况下不会造成ip碎片的最大尺寸是
The maximum size of UDP payload
that, most of the time, will not cause ip fragmentation is
MTU size of the host handling the PDU (most of the case it will be 1500) -
size of the IP header (20 bytes) -
size of UDP header (8 bytes)
1500 MTU - 20 IP hdr - 8 UDP hdr = 1472 bytes
@EJP 谈到了 534
字节,但我会将其修复为 508
.这是FOR SURE不会造成碎片的字节数,因为主机可以设置的最小MTU大小是576和IP header max size
可以是 60 字节
(508 = 576 MTU - 60 IP - 8 UDP)
@EJP talked about 534
bytes but I would fix it to 508
. This is the number of bytes that FOR SURE will not cause fragmentation, because the minimum MTU size that an host can set is 576 and IP header max size
can be 60 bytes
(508 = 576 MTU - 60 IP - 8 UDP)
顺便说一句,我会尝试使用 1472
字节,因为 1500
是一个足够标准的值.
By the way i'd try to go with 1472
bytes because 1500
is a standard-enough value.
如果您通过 PPPoE
连接,请使用 1492
而不是 1500
进行计算.
Use 1492
instead of 1500
for calculation if you're passing through a PPPoE
connection.
这篇关于最可靠和最有效的udp数据包大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!