Java 套接字和 TCP 调优

发布于 2024-08-05 12:57:05 字数 515 浏览 0 评论 0原文

我尝试用 Java 开发一个文件传输应用程序,以小程序作为客户端,以独立的 java 应用程序作为服务器(在数据中心托管的专用计算机上)。 我使用DataOutputStream/DataInputStream来传输双方的数据。 当我发送大量数据时,带宽变化很大:首先一切正常,然后 tcp 流在 40-50 秒内冻结,而没有任何传输,然后再次开始。

当我使用 Ethereal 查看 tcp 流时,我看到重复的 ack、快速重传和 tcp 重传。 但我不认为问题源于 Java:我在 FileZilla 中进行 FTP 传输时也遇到同样的问题。 但是......当我尝试使用netcat(netcat客户端+netcat服务器)传输数据时,一切都很好,带宽稳定,tcp丢失的数据包似乎立即重新传输,没有任何暂停,无论传输的量如何。

就好像 Java 不像 netcat 那样有能力玩 tcp 流......

我尝试玩 Socket.setSendBufferSize(),但我没有看到任何区别。 有什么想法吗?

谢谢 ! 抱歉我的英语不好......

I try to develop a file transfer application in Java, with an applet as client, and a standalone java app as server (on a dedicated machine hosted in a datacenter).
I use DataOutputStream/DataInputStream to transfers the data on both sides.
When I send big volumes of data, the bandwith is very variable : all is okay first, then the tcp stream is freezed during 40-50 seconds while nothing is transferring, and then it starts again.

When I look at the tcp stream with Ethereal, I see duplicate acks, fast retransmits, and tcp retransmits.
But I don't think that the problem is originating from Java : I have the same problem with FTP transfers in FileZilla.
But ... when I try to transfer data using netcat (netcat client + netcat server), all is fine, the bandwith is stable, the tcp lost packets seems to be retransmitted immediately without any pause, no matter of the volume transferred.

It's like if Java was not as talented as netcat to play with tcp streams ...

I tried to play with Socket.setSendBufferSize(), but I didn't see any difference.
Any idea ?

Thanks !
And sorry for my bad english ...

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

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

发布评论

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

评论(2

凑诗 2024-08-12 12:57:05

阿米奇夫先生是对的!
这与另一个线程上的问题相同。
通过将 DataXXXputStream 替换为 BufferedXXXputstream 解决了我的问题。
write(byte[], off, len) 方法是相同的,并且文档没有讨论这种不同的行为。 DataOutputStream 是缓冲的,BufferedOutputStream 也是缓冲的,但第二个做得更好。
谢谢 !

Mr amischiefr is right !
It's the same problem that on the other thread.
My problem was solved by replacing DataXXXputStream by BufferedXXXputstream.
The write(byte[], off, len) methods are the same, and the doc doesn't talk about such different behavior. DataOutputStream is buffered, BufferedOutputStream too, but the second one does it much better.
Thanks !

半窗疏影 2024-08-12 12:57:05

听起来更像是您的网络陷入困境,并且您看到 TCP 窗口(我相信这是正确的术语)基本上限制了您的带宽。

Sounds more like your network is bogged down and you are seeing TCP windowing (I believe that's the correct term) basically limiting your bandwidth.

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