7

I'm developing an FTP-like program to download a large number of small files onto an Xbox 360 devkit (which uses Winsock), and porting it to Playstation3 (also a devkit, and uses linux AFAIK). The program uses BSD-style sockets (TCP). Both of the programs communicate with the same server, downloading the same data. The program iterates through all the files in a loop like this:

for each file
    send(retrieve command)
    send(filename)
    receive(response)
    test response
    receive(size)
    receive(data)

On the Xbox 360 implementation, the whole download takes 1:27, and the time between the last send and first receive takes about 14 seconds. This seems quite reasonable to me.

The Playstation3 implementation takes 4:01 for the same data. The bottleneck seems to be between the last send and first receive, which takes up 3:43 of that time. The network and disk times are both significantly less than the Xbox 360.

Both these devkits are on the same switch as my PC, which does the file serving, and there is no other traffic on said switch.

I've tried setting the TCP_NODELAY flag, which didn't change things significantly. I've also tried setting the SO_SNDBUF/SO_RCVBUF to 625KB, which also didn't significantly affect the time.

I'm assuming that the difference lies between the TCP/IP stack implementations between Winsock and linux; is there some socket option that I could set to make the linux implementation behave more like Winsock? Is there something else I'm not accounting for?

The only solution looks to be to rewrite it so that it sends all the file requests together, then receives them all.

Unfortunately, Sony's implementation does not have the TCP_CORK option, so I cannot say if that is the difference.

4

2 回答 2

2

You want TCP_CORK. It'll prevent partial frames from being sent increasing throughput (at the expense of latency) - just like winsock.

int v,vlen;
v=1; vlen=sizeof(v);
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &v, &vlen);

Set v=0 to flush the frames before receive:

int v,vlen;
v=0; vlen=sizeof(v);
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &v, &vlen);

On most unixes you can improve your throughput further by using writev() or sendfile()...

于 2008-11-26T01:59:52.043 回答
1

Wireshark 是你的朋友,嗅探电线——查看数据包,看看每个数据包是如何排序的,看看你是否无法发现差异/问题。

在高延迟链接上,您确实希望确保尽可能多地缓冲每个 TCP 数据包。

发送合并通常是一个好主意。它仅在发送端有多个未确认帧排队时触发。通常,如果您知道自己在做什么并且您的系统提供全面的缓冲,您应该禁用此功能,否则禁用它肯定会对高延迟网络上的系统性能产生负面影响。

对于最高吞吐量,缓冲区分界应该是路径 MTU 的确切因素。

于 2008-11-26T03:49:22.883 回答