emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

optimization for pop movemail


From: Ken Raeburn
Subject: optimization for pop movemail
Date: Sun, 03 Jul 2005 19:01:26 -0400

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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]