From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Cross Message-Id: <200111261922.OAA12040@augusta.math.psu.edu> To: 9fans@cse.psu.edu Subject: Re: [9fans] Nagle algorithm In-Reply-To: References: <20011123115816.4863819A7E@mail.cse.psu.edu> Cc: Date: Mon, 26 Nov 2001 14:22:13 -0500 Topicbox-Message-UUID: 2a336362-eaca-11e9-9e20-41e7f4b1d025 In article you write: >forsyth@caldo.demon.co.uk writes: >> ... Nagle's algorithm for coalescing short segments, >> which is the one that seems ill-advised to me > >So, how many packets should the following code segment generate? > > #include > /* for int usleep(useconds_t microseconds); */ > > for(i=0; i < 200; i++) { > write(tcpfd, "a", 1); > usleep(100); > } Err, well, 200. Or less if the TCP implementation can coallese packets without incurring any additional latency. But that's what you wanted, right? It's what you wrote. If you wanted to buffer 200 ``a's'' before sending them, why not do that explicitly? #include #include FILE *fd = fdopen(tcpfd, "w"); for (i = 0; i < 200; i++) { fwrite("a", 1, 1, fd); usleep(100); } fflush(fd); If I'm not mistaken, that achieves the same effect, with far less overhead. The Plan 9 way might be to write a file system that overlays /net/tcp and introduces a buffering layer, kind of like what ssl(3) does. >> i do find that quite a lot of this smacks of trying to >> compensate for inadequate data provided by the protocol or the network. > >Abstraction and information-hiding are usually considered helpful. Right! So why do I want my TCP trying to figure out what my application is doing? All of a sudden, I'm no longer hiding information from the TCP; my abstraction is gone. >Who wants to muck around with RTT and pMTU in an application >which just might happen to write to a TCP connection? Why does the application care? I can pick a reasonable default; say, 8 or 16 or 32 or even 64 KB. >Perhaps cat(1) isn't complicated enough yet? cat(1) picks a reasonable default. :-) - Dan C.