在应用程序级别,比如说使用 java,我需要担心实际 TCP 数据包大小多少?因此,例如,我正在尝试编写一个应通过 TCP 套接字的输出流发送数据的应用程序,我是否必须始终考虑写入流的数据的大小?由于java套接字是流式套接字,我实际上没有考虑数据单元的大小,但是TSO(TCP分段卸载)对于OS/NIC来说是“打开”的,然后我可以将64KB数据片或MSS写入输出流并因此,尝试节省将数据切片至小于 1500 字节 (< MTU) 所需的宝贵 CPU 时间。就能够动态处理这个问题而言,我的编程有多有效?我知道我们可以使用 NetworkInterface.getMTU() 来确定操作系统/NIC MTU 大小,但不确定它如何提供帮助。 所以,我可以说,总的来说,我对如何最大化字节写入输出流的吞吐量有点困惑。
最佳答案
how much do I have to worry about the actual TCP packet size?
几乎从来没有。您可以设置NoTcpDelay(true);但这很少会产生影响。
So, for example, I am trying to write an application that should send data over TCP socket's outputstream, do I have to always keep into account the size of the data written to the stream?
我对此表示怀疑。如果您的连接速度为 1 Gb 或更慢,那么您将很难编写效率低下且无法使用此带宽的程序。
Since java sockets are streaming sockets, I havent actually considered the size of data units, but the TSO (TCP Segmentation offload) is "turned on" for the OS/NIC, then I can write a 64KB data slice or MSS to the outputstream and thus try to save the precious CPU time of slicing the data to less than 1500 bytes (< MTU).
我不明白如何让大多数像样的网络适配器支持 TCP 卸载。
How effective could my programming be, in terms of being able to take care of this dynamically?
Java 在任何情况下都不支持它。
I know we can get NetworkInterface.getMTU() to determine OS/NIC MTU size, but not sure how it can help that.
我也没有。
So, I can say that overall, I am a bit confused on how to maximize my throughput of byte writing to the outputstream.
在 Java 中可以做出的最重要的改变就是使用 NIO。我建议阻止 NIO,因为这是 NIO 的最简单的更改。如果您使用直接 ByteBuffer,这可以节省从 Java 到 native 内存的冗余内存拷贝。
您知道您在使用网络最大带宽时遇到问题吗?如果您没有测量过这就是问题的原因,那么这只是一个猜测。
关于java - 在应用程序级别调整 TCP 数据包大小以实现最大吞吐量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19139653/