预测 Java 应用程序生成的网络流量开销

发布于 2024-11-01 18:44:52 字数 540 浏览 2 评论 0原文

我想尝试计算我通过网络发送/接收的数据量(字节)。我发送/接收 TCP 和 UDP 数据包,因此我需要能够计算这些数据包的大小,包括它们各自的标头。我查看了这个问题:空 UDP 和 TCP 数据包的大小 和它列出了标题的最小大小,但是诽谤性的改变吗?我是否应该只添加在数据包中发送的字节数,但添加最小标头的大小?另外,我知道在某个时刻(n 个字节)数据会太大而无法容纳在一个数据包中。

另一件事是,客户端是移动设备,因此它可以通过蜂窝或 WiFi 接收。我不确定两者之间的数据包大小是否存在差异,但我可能只想假设更大的数据包。

所以我的问题是,假设数据有 n 个字节长:

1)假设 TCP 数据包全部适合一个数据包,那么 TCP 数据包有多大?

2) 假设 UDP 数据包全部装入一个数据包,那么该数据包有多大?

3)是否有一种简单的方法来确定超出一个数据包所需的字节数?对于 TCP 和 UDP。

I want to attempt to calculate how much data (bytes) I send/receive over the network. I send/receive both TCP and UDP packets, so I need to be able to calculate the size of these packets including their respective headers. I looked at this questions: Size of empty UDP and TCP packet and it lists the minimum size of the header, but is that libel to change? Should I just add the number of bytes I send in the packet, but the size of the minimum header? Also, I know at some point (n bytes) the data would be too big to fit in just one packet.

One other thing, the client is a mobile device, so it may receive over cellular or wifi. I am not sure if there is a difference in the packet size between the two, but I would probably just want to assume what ever is larger.

So my questions are, assuming the data is n bytes long:

1) How big would the TCP packet be, assuming it all fits in one packet?

2) How big would the UDP packet be, assuming it all fits in one packet?

3) Is there an easy way to determine the number of bytes it would take to overrun one packet? For both TCP and UDP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给我一枪 2024-11-08 18:44:52

假设我们只讨论以太网和 IPv4

Look at your interface MTU, which has already subtracted 
    the size of the ethernet headers for the OS I can 
    remember (linux and FreeBSD)

Subtract 20 bytes for a normal IP header (no IP options)

Subtract 20 bytes for a normal TCP header

Or

Subtract 8 bytes for a UDP header

这就是您可以将多少数据打包到一个 IPv4 数据包中。因此,如果您的 TCP 数据长度为 n 字节,则以太网总负载为 (n + 20 + 20);您的 UDP 以太网负载为 (n + 20 + 8)

编辑问题

回复:MTU

您的接口 MTU 是驱动程序允许您封装到线路上的最大以太网有效负载。我减去是因为我们假设我们从 MTU 开始并向上处理封装链(即 eth -> ip -> tcp|udp);您无法在没有 IP 标头的情况下发送 TCP 或 UDP,因此也必须考虑到这一点。

RE: 计算应用程序开销

关于应用程序将生成的开销的理论计算很好,但我 如果您想要有意义的数字,建议进行实验室测试每个客户端会话的平均数据传输每分钟客户端命中率并发客户端等使用因素在某些(异常)情况下可能会产生影响。

Lets assume we're only talking about ethernet and IPv4

Look at your interface MTU, which has already subtracted 
    the size of the ethernet headers for the OS I can 
    remember (linux and FreeBSD)

Subtract 20 bytes for a normal IP header (no IP options)

Subtract 20 bytes for a normal TCP header

Or

Subtract 8 bytes for a UDP header

That is how much data you can pack into one IPv4 packet. So, if your TCP data is n bytes long, your total ethernet payload is (n + 20 + 20); your ethernet payload for UDP is (n + 20 + 8).

EDIT FOR QUESTIONS

RE: MTU

Your interface MTU is the largest ethernet payload that your drivers will let you encapsulate onto the wire. I subtract because we're assuming we start from the MTU and work up the encapsulation chain (i.e. eth -> ip -> tcp|udp); you cant send TCP or UDP without an IP header, so that must be accounted for as well..

RE: Calculating application overhead

Theoretical calculations about the overhead your application will generate are fine, but I suggest lab testing if you want meaningful numbers. Usage factors like average data transfer per client session, client hit rate per minute and concurrent clients can make a difference in some (unusual) cases.

少女的英雄梦 2024-11-08 18:44:52

遗憾的是不可能完全确定这一点。数据包可能会在到达接收者的整个路径上被网络硬件分割、重组等,因此无法保证计算出准确的字节数。

以太网将帧大小定义为 1500 字节,如果减去标头,则剩余 1460 字节。通常仅在本地支持使用高达 9k 字节的巨型帧。当数据包到达 WAN 时,它将被分段。

It is sadly not possible to determine this completely. Packets might be split, reassembled etc. by network hardware all along the path to the receiver, so there is no guarantee to calculate the exact number of bytes.

Ethernet defines the frame size with 1500bytes, which makes 1460 bytes remaining if the headers are subtracted. Using jumbo frames up to 9k bytes is usually only supported locally. When the packet reaches the WAN, it will be fragmented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文