TCP消息合并 [英] TCP messages getting coalesced
问题描述
我有一个正在写入网络的Java应用程序.它正在764b +/- 5b范围内写入消息. pcap显示流正在IP碎片化,我们无法解释这一点.
I have a Java application that is writing to the network. It is writing messages in the region of 764b, +/- 5b. A pcap shows that the stream is getting IP fragmented and we can't explain this.
Linux 2.6.18-238.1.1.el5
Linux 2.6.18-238.1.1.el5
一条轨迹显示:
( strace -vvvv -f -tt -o strace.out -e trace = network -p $ PID )
1: 2045 12:48:23.984173 sendto(45, "\0\0\0\0\0\0\2\374\0\0\0\0\0\3\n\0\0\0\0\3upd\365myData"..., 764, 0, NULL, 0) = 764
2: 15206 12:48:23.984706 sendto(131, "\0\0\0\0\0\0\2\374\0\0\0\0\0\3\n\0\0\0\0\3upd\365myData"..., 764, 0, NULL, 0 <unfinished ...>
3: 2046 12:48:23.984811 sendto(46, "\0\0\0\0\0\0\2\374\0\0\0\0\0\3\n\0\0\0\0\3upd\365myData"..., 764, 0, NULL, 0 <unfinished ...>
4: 15206 12:48:23.984893 <... sendto resumed> ) = 764
5: 2046 12:48:23.984948 <... sendto resumed> ) = 764
捕获网络时,我看到的数据包大于MTU,这会导致碎片化.
I am seeing packets larger than the MTU when I capture the network, which is causing fragmentation.
4809 5.848987 10.0.0.2 -> 10.0.0.5 TCP 40656 > taiclock [ACK] Seq=325501 Ack=1 Win=46 Len=1448 TSV=344627654 TSER=270108068 # First Fragment
4810 5.848991 10.0.0.5 -> 10.0.0.2 TCP taiclock > 40656 [ACK] Seq=1 Ack=326949 Win=12287 Len=0 TSV=270108081 TSER=344627643 # TCP ack
4811 5.849037 10.0.0.2 -> 10.0.0.5 TCP 40656 > taiclock [PSH, ACK] Seq=326949 Ack=1 Win=46 Len=82 TSV=344627654 TSER=270108081 # Second Frag
问题:
1)似乎服务器试图将两个sendto()批处理到一个IP数据包中,该IP数据包比MTU大,因此变得碎片化.为什么?
1) It appears the server trying to batch the two sendto() into one IP packet, which is larger than the MTU and is therefore getting fragmented. Why?
2)查看PID 2046的strace输出,等号< ... sendto restarted>行之后的数字是否等于发送的总数? IE. 3行和5行总共发送了764b?还是每行发送764个字节?
2) Looking at the strace output for PID 2046, is the figure after the equal sign <... sendto resumed> line a total for what was sent? I.e. 764b was sent in total for line 3 and line 5? Or is 764 bytes being sent per line?
3)我可以传递给strace以记录sendto()输出的 all 的任何选项吗?似乎找不到任何东西.
3) Are there any options I can pass to strace to log all of the sendto() output? Can't seem to find anything..
推荐答案
要依次回答您的问题,
1)使用TCP时,合并多个发送调用是完全正常的,因为它是流协议,因此不会以任何方式保留用户级别的发送边界.在您的跟踪中,我看不到任何IP碎片的证据(这很糟糕),而TCP分段(完全正常)没有证据.
1) It is perfectly normal for multiple send calls to be coalesced when using TCP as it is a stream protocol so does not preserve user level send boundaries in any way. I don't see any evidence of IP fragmentation (which would be bad) in your trace, just of TCP segmentation (which is completely normal).
2)是的,这就是大小-更具体地说,它报告的是系统调用在恢复后返回的值.
2) Yes, that is the size - more specifically it is reporting the value that the system call returned after it resumed.
3)您可以使用"-e write = all"或"-e write ="来获取strace报告全部已写入的数据.
3) You can use "-e write=all" or "-e write=" to get strace to report the whole of the written data.
这篇关于TCP消息合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!