Morgan
Morgan

Reputation: 356

Does TCP Packet Size Affect Download Rate?

I have a project I'm working on where I have to send large blobs of binary data over a network connection, and due to various restraints, it would be easiest to use TCP wrappers. In short, what I mean is that I'm managing the packets (and the binary data) by hand.

My question is simple, though: Would the packet size affect the data transfer rate? The size of the packets and the buffer would change memory usage, I understand that, but what about the actual rate at which it transfers over the network? I mean, larger packets would mean fewer packets, so that would speed it up, but I would imagine that larger packets also transfer more slowly... Do they cancel out and it doesn't matter, or is one change greater than the other and it does make a difference? And in which direction?

I feel I should also point out, I'm also reading the data right from a file stream (one packet at a time, to be efficient with memory) and passing the binary data straight into a file stream (one packet at a time), so I don't know if that would affect the efficiency of the setup or the effect of the change in packet size.

Any help with this would be greatly appreciated.

Upvotes: 1

Views: 3800

Answers (2)

user207421
user207421

Reputation: 310869

I'm managing the packets (and the binary data) by hand

You're not. You might think you are, but you're not. TCP is specifically designed to coalesce outgoing data into the minimum number of packets, and there isn't much you can do about that.

Would the packet size affect the data transfer rate?

Of course. The fewer packets the better, to amortize the overhead. TCP packets have a minimum overhead of 40 bytes, so the bigger the better.

larger packets also transfer more slowly

Meaningless. You have to transfer X bytes, it takes as long as it takes. What you need to minimize is the overhead, which in space terms is the packet header.

Your best friend in terms of TCP throughput is a large socket receive buffer at the receiver, and your second-best friend is a large socket send buffer at the sender. Don't try to out-think TCP, it's been worked on by experts for over 30 years.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490088

Each packet has some fixed overhead (e.g., the source and destination addresses). The larger each packet, the smaller that fixed overhead becomes as a percentage of the whole. Therefore, larger packets increase throughput.

That said, unless you're really hacking into the IP stack, or setting something like TCP_NODELAY, the normal TCP implementation will try to accumulate data to send larger packets automatically.

Upvotes: 2

Related Questions