Re: Finding the optimal packet size

Doug McNaught (doug@mcnaught.org)
13 Dec 1999 18:02:58 -0500


"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:

> I'm writing an FTP server program. Earlier versions have just sent out
> 1460-byte chunks (using send()) at a time, which worked perfectly well
> on my machine (Ethernet, 2.2.0 through 2.2.13, MTU: 1500). But then, I
> test it on another machine (Ethernet, 2.2.5, MTU: 1500), and that machine
> _fragments_ the packet into 1448 and 12 byte chunks!
>
> Is there any portable way (both across Linux kernels, and possibly also
> to other Unices, such as Solaris) I could find the `right' MTU, and have
> the kernel send packets of _only_ that size? (I'd like to send only one
> packet at once, if that's possible.) If not, why does one machine differ
> from the other? (They're using the same glibc2 compilation, even.)

The best and most portable (and efficient) way is to do write() or
send() with a large buffer (the bigger the better, modulo RAM
constraints). TCP will do PMTU discovery for you and set the MSS as
large as possible. If you're sending a real file (rather than
dynamically generated data) you can mmap() the file, which keeps you
from having to explicitly read it into memory, then call send() on the
mmap()'ed buffer.

Is there some reason you need to send one packet at a time? It's
horrendously inefficient--the goal is to minimize the number of
syscalls you make, and one per packet is a very large overhead.

-Doug

-- 
Doug McNaught       doug@mcnaught.org     http://www.mcnaught.org/~doug

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/