unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* optimization for pop movemail
@ 2005-07-03 23:01 Ken Raeburn
  2005-07-04 16:48 ` Richard M. Stallman
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Raeburn @ 2005-07-03 23:01 UTC (permalink / raw)



The POP support in movemail runs afoul of a combination of otherwise
reasonable optimizations in most TCP stacks, Nagle and delayed acks.
It sends (for example) "RETR 1234" and then there's a delay before it
sends "\r\n", because we make two write() calls.  It can add something
like 0.4 seconds per message retrieved, which adds up with a lot of
messages.

Is this approach okay, or should I go change the code to include the
\r\n at all the call sites instead?
Should this wait until after the release?

Ken


--- lib-src/pop.c	1 Sep 2003 15:45:03 -0000	1.34
+++ lib-src/pop.c	3 Jul 2005 22:04:03 -0000
@@ -1404,10 +1393,39 @@ sendline (server, line)
 #define SENDLINE_ERROR "Error writing to POP server: "
   int ret;
 
-  ret = fullwrite (server->file, line, strlen (line));
-  if (ret >= 0)
-    {				/* 0 indicates that a blank line was written */
-      ret = fullwrite (server->file, "\r\n", 2);
+  if (line == pop_error && strlen (line) < sizeof (pop_error) - 5)
+    {
+      /* This minor "abstraction" violation can save a fraction of a
+	 second per message sent in a fast, reliable TCP network
+	 environment with delayed acks and Nagle algorithm.  (Movemail
+	 writes line without \r\n, client kernel sends it, server
+	 kernel delays ack to see if it can combine it with data,
+	 movemail writes \r\n, client kernel waits because it has
+	 unacked data, client kernel eventually times out and sends.)
+
+	 On a NetBSD box, this delay is 0.2 seconds per message; if
+	 you've got a few dozen messages or so, it adds up, and if
+	 they're small and the server is close, it can be a
+	 significant fraction of the execution time.
+
+	 Turning off Nagle would probably change this to two packets
+	 in rapid succession for most implementations.  If we can make
+	 it just one write call, we'll likely get one packet and keep
+	 everybody happier.
+
+	 Fortunately, most of the formatted calls (e.g., all those
+	 including message numbers) use pop_error as the buffer
+	 into which the command is written.  */
+      strcat (line, "\r\n");
+      ret = fullwrite (server->file, line, strlen (line));
+    }
+  else
+    {
+      ret = fullwrite (server->file, line, strlen (line));
+      if (ret >= 0)
+	{	       /* 0 indicates that a blank line was written */
+	  ret = fullwrite (server->file, "\r\n", 2);
+	}
     }
 
   if (ret < 0)

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

end of thread, other threads:[~2005-07-05 19:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-03 23:01 optimization for pop movemail Ken Raeburn
2005-07-04 16:48 ` Richard M. Stallman
2005-07-05  7:00   ` Ken Raeburn
2005-07-05 19:11     ` Richard M. Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).