unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
Subject: optimization for pop movemail
Date: Sun, 03 Jul 2005 19:01:26 -0400	[thread overview]
Message-ID: <E1DpDSo-0001vd-00@kal-el.raeburn.org> (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)

             reply	other threads:[~2005-07-03 23:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-03 23:01 Ken Raeburn [this message]
2005-07-04 16:48 ` optimization for pop movemail Richard M. Stallman
2005-07-05  7:00   ` Ken Raeburn
2005-07-05 19:11     ` Richard M. Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1DpDSo-0001vd-00@kal-el.raeburn.org \
    --to=raeburn@raeburn.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).