Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* UDP and TCP message limits?
@ 1996-05-22  4:00 John Chambers
  1996-05-22  4:00 ` W. Richard Stevens
  0 siblings, 1 reply; 2+ messages in thread
From: John Chambers @ 1996-05-22  4:00 UTC (permalink / raw)



Is there some systematic way that a person (or even better, a program)
might  learn about the limits to what can be written successfully to a
UDP or TCP socket and received by the other end?

What triggers this is that I just spent (some might say wasted  ;-)  a
couple  of  days  learning  that  on DEC's OSF1, a UDP packet can't be
larger that 9216 bytes, and you can't  successfully  write  more  than
40960  bytes  to  a TCP socket in a single write.  In the UDP case, it
tells you by returning -1 with errno=40 (EMSGSIZE ,  or  "Message  too
long:).   In  the  TCP case, you don't get an error if you write 40961
bytes; the recipient just doesn't get a return from the select() call.

The TCP case may be a bug (but one that must be programmed  around  if
you  don't  want  to  wait forever for a fix or you want it to work on
already-delivered systems).  The UDP case  is  obviously  intentional.
Neither seems to be documented, or easy to learn about.

These are, of course, totally weird numbers, and I'd expect them to be
different on different systems.  So I asked on a couple of newsgroups.
I posted this to comp.os.linux.misc, because I'm  looking  forward  to
trying  some  of the software on linux, and I'm wondering if there's a
way to shortcut the painful process of learning about such limits.  It
seems that if anyone knows, it might be the linux people.


The main motive for wanting this,  of  course,  is  that  when  you're
trying  to  get  large  chunks  of data across the network quickly, it
turns out that on most systems, the only  important  variable  is  how
many  system calls you do.  Thus, with UDP, you typically have a limit
to the number of sendto() and recvfrom() calls  per  second,  and  the
sizes of the packets is (almost) irrelevant.  So you need to learn the
max packet size that you can get the two machines to accept.

Similarly, with TCP, the fastest data transfer *should* be to  open  a
file  and read it into memory with one read() (or memory-map it if you
can), then send it down the pipe with a single write(). But this turns
out  to  never  work;  your  TCP  invariably has some secret limit and
either won't accept more, or even worse, will pretend  to  accept  the
data  but  just  won't  deliver  it  (correctly).   So to get the best
performance, you need to learn the max message size that the TCP  link
will do (correctly).

Does anyone know the corresponding UDP and TCP max-message limits  for
linux?   How about for your other favorite Unix-like system?  For that
matter, how about for some IPs on non-Unix-like systems?


Any good ideas for learning these magic numbers?  Anyone got a  clever
chunk of code that's known to work on N different systems?


(BTW, don't bother telling me about the evils of  fragmentation.   I'm
all too familiar with them. But if you have more than one MTU of data,
*someone* must do fragmentation.  It's merely a  question  of  whether
it's done in the application or in the kernel.  The high overhead of a
system call says that you want it done in the kernel if possible.  One
way of expressing the question is:  How large a message can a system's
UDP or TCP layer accept and fragment correctly?)


(Golly gee; I hope this doesn't start a flame war! ;-)


--
#!/usr/bin/perl -s-- -export-a-crypto-system-sig -RSA-in-3-lines-PERL
($k,$n)=@ARGV;$m=unpack(H.$w,$m."\0"x$w),$_=`echo "16do$w 2+4Oi0$d*-^1[d2%
Sa2/d0<X+d*La1=z\U$n%0]SX$k"[$m*]\EszlXx++p|dc`,s/^.|\W//g,print pack('H*'
,$_)while read(STDIN,$m,($w=2*$d-1+length($n||die"$0 [-d] k n\n")&~1)/2)



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: UDP and TCP message limits?
  1996-05-22  4:00 UDP and TCP message limits? John Chambers
@ 1996-05-22  4:00 ` W. Richard Stevens
  0 siblings, 0 replies; 2+ messages in thread
From: W. Richard Stevens @ 1996-05-22  4:00 UTC (permalink / raw)



> Is there some systematic way that a person (or even better, a program)
> might  learn about the limits to what can be written successfully to a
> UDP or TCP socket and received by the other end?

UDP: the socket send buffer size is the limit on the largest UDP datagram
that you can send (SO_SNDBUF).  If it's not big enough, increase it with
setsockopt().

TCP: you should be able to write as much as you want, and if this exceeds
the socket send buffer size, you are just put to sleep.  (This assume the
default blocking socket.)  what you describe sounds like a bug.

> These are, of course, totally weird numbers, and I'd expect them to be
> different on different systems.

The UDP limit of 9216 = 8192 + 1024.  It's for 8k of data, plus the
IP/UDP/RPC headers for an NFS request.

	Rich Stevens



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-05-22  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-05-22  4:00 UDP and TCP message limits? John Chambers
1996-05-22  4:00 ` W. Richard Stevens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox