From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1103af,f7be7fce5647049e,start X-Google-Attributes: gid1103af,public X-Google-Thread: f9325,f7be7fce5647049e,start X-Google-Attributes: gidf9325,public X-Google-Thread: f678f,f7be7fce5647049e,start X-Google-Attributes: gidf678f,public From: jc@eddie.mit.edu (John Chambers) Subject: UDP and TCP message limits? Date: 1996/05/22 Message-ID: <4nttm0$kh2@MICRO-HEART-OF-GOLD.MIT.EDU>#1/1 X-Deja-AN: 156056226 organization: Has not been determined. reply-to: jc@eddie.mit.edu newsgroups: comp.os.linux.misc,comp.unix.osf.misc,comp.protocols.tcp-ip 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