summaryrefslogtreecommitdiff
path: root/performance.mdwn
blob: 90995ed2089f4af9fad8151deddfbcb07e53646e (plain)
[[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
# Optimize notmuch's performance

[[!toc levels=2]]

## Use of ecryptfs slows notmuch down.

I noticed that my `notmuch new` was really slow (several minutes) for
less then 20 new emails (around 20K in my database).

The performance tests in the notmuch source didn't show any real
issue, even on a non-encrypted ext4 fs.

After investigation and running different tests, a switch to a
LUKS-btrfs based filesystem to replace the ext4-ecryptfs resolved the
issue. It now takes some seconds to index hundreds of messages.

## Xapian database format: chert vs. flint vs. glass

Depending on the Xapian version that was used during the initial notmuch
database creation, you might use another database format than the most recent
one, which is often faster.

Check whether you are on chert, flint or glass:

    $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
    iamglass

If it does not say `iamglass`, but `iamchert` or `iamflint`, than you should
migrate (read on).

There might be a file named `flintlock`, it is no indicator for your database
format, but also used in case of `chert`.

### Migrate from an older format to the most recent one (glass)

Make sure you are using xapian 1.4.x (depends on your distribution)

XXX: add examples for different distributions

Backup your notmuch tags:

    $ cd
    $ notmuch dump --output=notmuch-dump-oldformat

Move away your old database:

    $ mv $(notmuch config get database.path)/.notmuch/ notmuch-db.bak

Find and import your messages, a new and fresh database will be
created:

    $ notmuch new

Restore your tags:

    $ notmuch restore --input=notmuch-dump-oldformat

Check whether you are on glass now:

    $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
    iamglass

  If it says `iamflint` or `iamchert`, most likely you are still using an old
  xapian version.

Clean-up: if you are sure everything is fine, you can delete the old
things. The dump of your tags you might want to keep anyway as a
backup - on the other hand you should have some mechanism in place to
make regular backups of your notmuch database:

    $ rm notmuch-dump-oldformat
    $ rm -R notmuch-db.bak

### Compact your database

In order to greatly reduce the size of your database, you should compact it. 
This can be easily achieved with `notmuch compact`:

    $ notmuch compact

Note that this process can take a long time for large database and a write lock
will be held for the duration to ensure data integrity. The process will create
a new compacted database in a temporary directory and finally replace the
original database if compaction is successful. For added safety you can provide
`--backup=<directory>` option to preserve a copy of the original database. For
more details on this process see `notmuch-compact` man page.

### Performance test suite

Notmuch ships with a [[performance test suite|perf-test]] which uses a downloadable
[[corpus]] of email.

### More information about this in the email archives:

* [Carl Worth](https://notmuchmail.org/pipermail/notmuch/2010/001105.html)

* [Sebastian Spaeth](https://notmuchmail.org/pipermail/notmuch/2011/004048.html)

* [Pieter Praet](https://notmuchmail.org/pipermail/notmuch/2011/004175.html)