Re: [notmuch] [PATCH] Calls to notmuch get queued and executed asynchronously.
authorAaron Ecay <aaronecay@gmail.com>
Fri, 30 Dec 2011 19:21:31 +0000 (14:21 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:26 +0000 (09:41 -0800)
fd/cf86b4c70de87b31e52d7b02a9dcc6a27ad146 [new file with mode: 0644]

diff --git a/fd/cf86b4c70de87b31e52d7b02a9dcc6a27ad146 b/fd/cf86b4c70de87b31e52d7b02a9dcc6a27ad146
new file mode 100644 (file)
index 0000000..6b6cbfb
--- /dev/null
@@ -0,0 +1,224 @@
+Return-Path: <aaronecay@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1B572431FD0\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:37 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 4Ung7nFkOffl for <notmuch@notmuchmail.org>;\r
+       Fri, 30 Dec 2011 11:21:36 -0800 (PST)\r
+Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
+       [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 25CF9431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:36 -0800 (PST)\r
+Received: by qcha6 with SMTP id a6so10926363qch.26\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 11:21:35 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type:content-transfer-encoding;\r
+       bh=eLNsZoQdbyC+rNy7SA8Zlys2EmuyV4xuFTX4veog434=;\r
+       b=RH3swbhzSQGVGNXlPtsub3Xnn3HSzSiITKsFsidXGIdVmWS3iUkp8YzVdXDv6KcYpP\r
+       bR1NXDPD5IZrrnuwarPKFd8AHWDmVj4TDgDjGtxi459O+MDW8baqzUtO8GgQSjzCO3NZ\r
+       QTZuYZevNNeimTSlPyRNawjc8x2ZZd015bYhI=\r
+Received: by 10.229.78.163 with SMTP id l35mr11757544qck.32.1325272895448;\r
+       Fri, 30 Dec 2011 11:21:35 -0800 (PST)\r
+Received: from localhost (24-158-179-191.dhcp.jcsn.tn.charter.com.\r
+       [24.158.179.191])\r
+       by mx.google.com with ESMTPS id df3sm74088306qab.6.2011.12.30.11.21.33\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Fri, 30 Dec 2011 11:21:34 -0800 (PST)\r
+From: Aaron Ecay <aaronecay@gmail.com>\r
+To: David Edmondson <dme@dme.org>, Daniel Schoepe <daniel@schoepe.org>,\r
+       James Vasile <james@hackervisions.org>, notmuch@notmuchmail.org\r
+Subject: Re: [notmuch] [PATCH] Calls to notmuch get queued and executed\r
+       asynchronously.\r
+In-Reply-To: <cun4nwi8h7i.fsf@hotblack-desiato.hh.sledj.net>\r
+References: <87vddnlxos.wl%james@hackervisions.org>\r
+       <87wrbykr13.fsf@gilead.invalid>\r
+       <cun4nwi8h7i.fsf@hotblack-desiato.hh.sledj.net>\r
+User-Agent: Notmuch/0.10.1+56~gd709fd6 (http://notmuchmail.org)\r
+       Emacs/24.0.92.3 (i386-apple-darwin10.8.0)\r
+Date: Fri, 30 Dec 2011 14:21:31 -0500\r
+Message-ID: <m2fwg1uapw.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 30 Dec 2011 19:21:37 -0000\r
+\r
+On Fri, 30 Dec 2011 10:52:17 +0000, David Edmondson <dme@dme.org> wrote:\r
+> > I discovered this patch a while ago and it almost applies cleanly (the\r
+> > conflicts are easy to fix though) and it has made the emacs UI for\r
+> > notmuch _much_ more responsive and enjoyable for me.\r
+\r
+This is definitely true for me as well.  So much so that I reinvented\r
+this patch from scratch a couple of weeks ago.  (As Picasso said, good\r
+artists copy, great artists steal.)\r
+\r
+> > As discussed on IRC, issues such as where to handle retries in case\r
+> > the database is locked should probably be handled in the notmuch\r
+> > binary instead of each UI.\r
+\r
+Hmm.  When my implementation detects that it cannot get the DB lock\r
+after trying several times (up to ~2 mins of waiting), it stops\r
+trying but continues to queue up operations.  The user can then\r
+manually restart the queue.  This isn=E2=80=99t a principled solution, but\r
+it avoids losing tagging operations from emacs while a long-running\r
+process has the DB locked.  (My original motivation for writing the\r
+patch was actually that my new-mail script sometimes holds the DB\r
+lock when I am trying to read mail, leading to emacs errors and\r
+dropped tagging operations.  The speedup was a welcome side effect.)\r
+\r
+I haven=E2=80=99t had a chance to carefully look at the patch you found, so=\r
+ IDK\r
+what its behavior would be in this case.\r
+\r
+(The other thing that I dislike about the patch you found is that it\r
+uses a call to the =E2=80=9Csleep=E2=80=9D command to wait, rather than usi=\r
+ng built-in\r
+emacs functionality.)\r
+\r
+> It would be good to have an updated version of this patch if it is still\r
+> considered useful, though I don't suffer particularly from lag in the\r
+> emacs UI.\r
+\r
+The emacs UI has small delays, which dropped away when I applied my\r
+version of this patch.  After being conditioned to expect them, I was\r
+surprised to find how much faster everything seemed.  My hardware is old\r
+but not ancient (5.5 year old Macbook; I suspect the bottleneck for\r
+notmuch is the 5400rpm HDD).  Depending on your setup, you too might be\r
+pleasantly surprised.\r
+\r
+The test suite is borked on OS X and I don=E2=80=99t have access to a linux\r
+machine while traveling.  I was planning on sending my patch in early\r
+Jan. when I had a chance to verify it under the test suite (probably\r
+requiring some changes to the emacs test library to make it async-safe).\r
+I also haven=E2=80=99t tested the patch on Emacs versions older than 24 =E2=\r
+=80=93 but I\r
+don=E2=80=99t think there are any impediments to compatibility with v.23 (n=\r
+ot\r
+sure about earlier versions).\r
+\r
+Since there is interest, I=E2=80=99ll go ahead and send it now with all the\r
+usual caveats about code under development.  I have been using the patch\r
+for a couple of weeks without problems, though.  Daniel, if you want to\r
+un-conflict (and squash) the patches from James that might be useful, at\r
+least to compare the two approaches.\r
+\r
+Aaron\r
+\r
+-----cut-here-----\r
+\r
+>From f0a0fe04254d9b5e17c873b293c6a5a270cb909a Mon Sep 17 00:00:00 2001\r
+From: Aaron Ecay <aaronecay@gmail.com>\r
+Date: Mon, 19 Dec 2011 12:14:31 -0500\r
+Subject: [PATCH] [emacs] add async tagging support\r
+\r
+still a WIP\r
+---\r
+ emacs/notmuch.el |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++=\r
++++-\r
+ 1 files changed, 54 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index fde2377..ca077c2 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -446,6 +446,59 @@ Complete list of currently available key bindings:\r
+   (let ((message-id (notmuch-search-find-thread-id)))\r
+     (notmuch-mua-new-reply message-id prompt-for-sender)))\r
+=20\r
++(defvar notmuch-process-queue nil\r
++  "Queue of pending notmuch tag operations.\r
++\r
++Each entry in the queue is a list of strings, which are arguments\r
++to be passed to the notmuch command.")\r
++\r
++(defvar notmuch-process-current-command nil\r
++  "The currently executing notmuch command arguments")\r
++\r
++(defvar notmuch-process-wait-time 1.0\r
++  "How long to wait for the db lock, in seconds.")\r
++\r
++(defvar notmuch-process-error nil)\r
++\r
++(defun notmuch-process-restart-queue ()\r
++  (interactive)\r
++  (setq notmuch-process-error nil)\r
++  (notmuch-process-kick-queue))\r
++\r
++(defun notmuch-process-kick-queue ()\r
++  (when notmuch-process-error\r
++    ;; TODO: better error msg, tell how to manually kick\r
++    (error "Notmuch couldn't get the DB lock after trying for more than a =\r
+minute."))\r
++  (when (and notmuch-process-queue\r
++           (memq (process-status "notmuch") '(exit nil)))\r
++    (let ((args (car notmuch-process-queue))\r
++        proc)\r
++      (setq notmuch-process-queue (cdr notmuch-process-queue)\r
++          notmuch-process-current-command args\r
++          proc (apply #'start-process "notmuch"\r
++                      (get-buffer-create "*Notmuch output*")\r
++                      notmuch-command args))\r
++      (set-process-sentinel proc #'notmuch-process-sentinel))))\r
++\r
++(defun notmuch-process-sentinel (proc status)\r
++  (if (equal status "finished\n")\r
++      (progn\r
++      (setq notmuch-process-wait-time 1.0\r
++            notmuch-process-current-command nil)\r
++      (notmuch-process-kick-queue))\r
++    (setq notmuch-process-wait-time (* 2 notmuch-process-wait-time)\r
++        notmuch-process-queue (cons notmuch-process-current-command\r
++                                    notmuch-process-queue))\r
++    (if (<=3D notmuch-process-wait-time 64)\r
++      (progn\r
++        (run-at-time notmuch-process-wait-time nil\r
++                     #'notmuch-process-kick-queue))\r
++      (setq notmuch-process-error t))))\r
++\r
++(defun notmuch-process-queue-command (&rest args)\r
++  (setq notmuch-process-queue (append notmuch-process-queue (list args)))\r
++  (notmuch-process-kick-queue))\r
++\r
+ (defun notmuch-call-notmuch-process (&rest args)\r
+   "Synchronously invoke \"notmuch\" with the given list of arguments.\r
+=20\r
+@@ -474,7 +527,7 @@ messages instead of running (notmuch-call-notmuch-proce=\r
+ss \"tag\" ..)\r
+ directly, so that hooks specified in notmuch-before-tag-hook and\r
+ notmuch-after-tag-hook will be run."\r
+   (run-hooks 'notmuch-before-tag-hook)\r
+-  (apply 'notmuch-call-notmuch-process\r
++  (apply 'notmuch-process-queue-command\r
+        (append (list "tag") tags (list "--" query)))\r
+   (run-hooks 'notmuch-after-tag-hook))\r
+=20\r
+--=20\r
+1.7.8.2\r
+\r
+-----cut-here-----\r
+\r
+--=20\r
+Aaron Ecay\r