如何确定TCP / IP中的总数据上传+下载

时间:2021-05-23 19:32:32

I need to calculate total data transfer while transferring a fixed size data from client to server in TCP/IP. It includes connecting to the server, sending request,header, receiving response, receiving data etc.

我需要计算总数据传输,同时在TCP / IP中将固定大小的数据从客户端传输到服务器。它包括连接到服务器,发送请求,标头,接收响应,接收数据等。

More precisely, how to get total data transfer while using POST and GET method?

更准确地说,如何在使用POST和GET方法的同时获得总数据传输?

Is there any formula for that? Even a theoretical one will do fine (not considering packet loss or connection retries etc)

那有什么公式吗?即使是理论上的也会很好(不考虑数据包丢失或连接重试等)

FYI I tried RFC2616 and RFC1180. But those are going over my head.

仅供参考我尝试了RFC2616和RFC1180。但这些都是我的头脑。

Any suggestion?

Thanks in advance.

提前致谢。

2 个解决方案

#1


You can't know the total transfer size in advance, even ignoring retransmits. There are several things that will stop you:

您无法提前知道总传输大小,甚至无法重新传输。有几件事会阻止你:

  • TCP options are negotiated between the hosts when the connection is established. Some options (e.g., timestamp) add additional data to the TCP header
  • 建立连接时,在主机之间协商TCP选项。一些选项(例如,时间戳)将附加数据添加到TCP报头

  • "total data transfer size" is not clear. Ethernet, for example, adds quite a few more bits on top of whatever IP used. 802.11 (wireless) will add even more. So do HDLC or PPP going over a T1. Don't even think about frame relay. Some links may use compression (which will reduce the total size). The total size depends on where you measure it, even for a single packet.
  • “总数据传输大小”尚不清楚。例如,以太网在所使用的IP之上增加了不少比特。 802.11(无线)将增加更多。通过T1进行HDLC或PPP也是如此。甚至不要考虑帧中继。某些链接可能使用压缩(这将减少总大小)。总大小取决于您测量它的位置,即使对于单个数据包也是如此。

  • Assuming you're just interested in the total octet size at layer 2, and you know the TCP options that will be negotiated in advance, you still can't know the path MTU. Which may change, even while the connection is in progress. Or if you're not doing path MTU discovery (which would be wierd), then the packet may get fragmented somewhere, and the remote end will see a different amount of data transfer than you.
  • 假设您只对第2层的八位字节总大小感兴趣,并且您知道将提前协商的TCP选项,您仍然无法知道路径MTU。即使在连接正在进行时,这可能会发生变化。或者,如果您没有进行路径MTU发现(这将是奇怪的),那么数据包可能会在某处碎片化,并且远程端将看到与您不同的数据传输量。

I'm not sure why you need to know this, but I suggest that:

我不知道为什么你需要知道这一点,但我建议:

  • If you just want an estimate, watch a typical connection in Wireshark. Calculate the percent overhead (vs. the size of data you gave to TCP, and received from TCP). Use that number to estimate: it will be close enough, except in pathological situations.
  • 如果您只想估算一下,请观看Wireshark中的典型连接。计算开销百分比(相对于您为TCP提供的数据的大小,以及从TCP接收的数据)。使用该数字进行估计:除病理情况外,它将足够接近。

  • If you need to know for sure how much data your end saw transmitted and received, use libpcap to capture the packet stream and check.
  • 如果您需要确定您的终端发送和接收的数据量,请使用libpcap捕获数据包流并进行检查。

#2


i'd say on average that request and response have about 8 lines of headers each and about 30 chars per line. Then allow for the size increase of converting any uploaded binary to Base64.

我平均说请求和响应每个大约有8行标题,每行约30个字符。然后允许将任何上传的二进制文件转换为Base64的大小增加。

You didn't say if you also want to count TCP packet headers, in which case you could assume an MTU of about 1500 so add 16 bytes (tcp header) per 1500 data bytes

你没有说你是否也想计算TCP数据包头,在这种情况下你可以假设一个大约1500的MTU,所以每1500个数据字节添加16个字节(tcp头)

Finally, you could always setup a packet sniffer and count actual bytes for a sample of data.

最后,您始终可以设置数据包嗅探器并计算数据样本的实际字节数。

oh yeah, and you may need to allow for deflate/gzip encoding as well.

哦,是的,你可能还需要允许deflate / gzip编码。

#1


You can't know the total transfer size in advance, even ignoring retransmits. There are several things that will stop you:

您无法提前知道总传输大小,甚至无法重新传输。有几件事会阻止你:

  • TCP options are negotiated between the hosts when the connection is established. Some options (e.g., timestamp) add additional data to the TCP header
  • 建立连接时,在主机之间协商TCP选项。一些选项(例如,时间戳)将附加数据添加到TCP报头

  • "total data transfer size" is not clear. Ethernet, for example, adds quite a few more bits on top of whatever IP used. 802.11 (wireless) will add even more. So do HDLC or PPP going over a T1. Don't even think about frame relay. Some links may use compression (which will reduce the total size). The total size depends on where you measure it, even for a single packet.
  • “总数据传输大小”尚不清楚。例如,以太网在所使用的IP之上增加了不少比特。 802.11(无线)将增加更多。通过T1进行HDLC或PPP也是如此。甚至不要考虑帧中继。某些链接可能使用压缩(这将减少总大小)。总大小取决于您测量它的位置,即使对于单个数据包也是如此。

  • Assuming you're just interested in the total octet size at layer 2, and you know the TCP options that will be negotiated in advance, you still can't know the path MTU. Which may change, even while the connection is in progress. Or if you're not doing path MTU discovery (which would be wierd), then the packet may get fragmented somewhere, and the remote end will see a different amount of data transfer than you.
  • 假设您只对第2层的八位字节总大小感兴趣,并且您知道将提前协商的TCP选项,您仍然无法知道路径MTU。即使在连接正在进行时,这可能会发生变化。或者,如果您没有进行路径MTU发现(这将是奇怪的),那么数据包可能会在某处碎片化,并且远程端将看到与您不同的数据传输量。

I'm not sure why you need to know this, but I suggest that:

我不知道为什么你需要知道这一点,但我建议:

  • If you just want an estimate, watch a typical connection in Wireshark. Calculate the percent overhead (vs. the size of data you gave to TCP, and received from TCP). Use that number to estimate: it will be close enough, except in pathological situations.
  • 如果您只想估算一下,请观看Wireshark中的典型连接。计算开销百分比(相对于您为TCP提供的数据的大小,以及从TCP接收的数据)。使用该数字进行估计:除病理情况外,它将足够接近。

  • If you need to know for sure how much data your end saw transmitted and received, use libpcap to capture the packet stream and check.
  • 如果您需要确定您的终端发送和接收的数据量,请使用libpcap捕获数据包流并进行检查。

#2


i'd say on average that request and response have about 8 lines of headers each and about 30 chars per line. Then allow for the size increase of converting any uploaded binary to Base64.

我平均说请求和响应每个大约有8行标题,每行约30个字符。然后允许将任何上传的二进制文件转换为Base64的大小增加。

You didn't say if you also want to count TCP packet headers, in which case you could assume an MTU of about 1500 so add 16 bytes (tcp header) per 1500 data bytes

你没有说你是否也想计算TCP数据包头,在这种情况下你可以假设一个大约1500的MTU,所以每1500个数据字节添加16个字节(tcp头)

Finally, you could always setup a packet sniffer and count actual bytes for a sample of data.

最后,您始终可以设置数据包嗅探器并计算数据样本的实际字节数。

oh yeah, and you may need to allow for deflate/gzip encoding as well.

哦,是的,你可能还需要允许deflate / gzip编码。