]> git.cworth.org Git - notmuch-wiki/blob - performance.mdwn
notmuchmail.org and git.notmuchmail.org are both available over https
[notmuch-wiki] / performance.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Optimize notmuch's performance
3
4 [[!toc levels=2]]
5
6 ## Use of ecryptfs slows notmuch down.
7
8 I noticed that my `notmuch new` was really slow (several minutes) for
9 less then 20 new emails (around 20K in my database).
10
11 The performance tests in the notmuch source didn't show any real
12 issue, even on a non-encrypted ext4 fs.
13
14 After investigation and running different tests, a switch to a
15 LUKS-btrfs based filesystem to replace the ext4-ecryptfs resolved the
16 issue. It now takes some seconds to index hundreds of messages.
17
18 ## Xapian 1.2.x database format: chert vs. flint
19
20 Xapian 1.2 (in contrast to 1.0.x) uses a new database format called
21 `chert` which is a lot faster than the old format `flint`.
22
23 Check whether you are on chert or flint:
24
25     $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
26     iamchert
27
28 If it does not say `iamchert`, but `iamflint`, than you should migrate
29 (read on).
30
31 There might be a file named `flintlock`, it is no indicator for your
32 database format, but also used in case of `chert`.
33
34 ### Migrate from flint to chert
35
36 Make sure you are using xapian 1.2.x (depends on your distribution)
37
38 XXX: add examples for different distributions
39
40 Backup your notmuch tags:
41
42     $ cd
43     $ notmuch dump --output=notmuch-dump-b4chert
44
45 Move away your old database:
46
47     $ mv $(notmuch config get database.path)/.notmuch/ notmuch-db-b4chert
48
49 Find and import your messages, a new and fresh database will be
50 created:
51
52     $ XAPIAN_PREFER_CHERT=1 notmuch new
53
54 I did not need the `XAPIAN_PREFER_CHERT`, but am not sure whether
55 there are situations making it necessary (certain compile-time options
56 to xapian?). This note is just here to be extended or removed by
57 somebody more knowledgeable.
58
59 After the initial import it is definitely not necessary to define
60 `XAPIAN_PREFER_CHERT` for subsequent calls of `notmuch new`.
61
62 Restore your tags:
63
64     $ notmuch restore --input=notmuch-dump-b4chert
65
66 Check whether you are on chert now:
67
68     $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
69     iamchert
70
71   If it says `iamflint`, most likely you are still using xapian 1.0.x.
72
73 Clean-up: if you are sure everything is fine, you can delete the old
74 things. The dump of your tags you might want to keep anyway as a
75 backup - on the other hand you should have some mechanism in place to
76 make regular backups of your notmuch database:
77
78     $ rm notmuch-dump-b4chert
79     $ rm -R notmuch-db-b4chert
80
81 ### Compact your database
82
83 In order to greatly reduce the size of your database, you should
84 compact it. Carl says "This functionality is not yet available in the
85 Xapian library interface or else I would probably make notmuch call it
86 after building the database." and Pieter "[compacting] will cause
87 writes to be a bit more expensive in the short term, but will
88 significantly reduce the db's size, which your SSD will surely
89 appreciate."
90
91 This needs xapian 1.2
92
93 Backup your database:
94
95     $ cd
96     $ notmuch dump --output=notmuch-dump-b4compact
97
98 Compact it:
99
100     $ cd $(notmuch config get database.path)/.notmuch
101     $ xapian-compact --no-renumber xapian xapian-compacted
102
103 Remove old and renamed compacted, if compacting went well:
104
105     $ rm -R xapian
106     $ mv xapian-compacted xapian
107
108
109 ### More information about this in the email archives:
110
111 * [Carl Worth](https://notmuchmail.org/pipermail/notmuch/2010/001105.html)
112
113 * [Sebastian Spaeth](https://notmuchmail.org/pipermail/notmuch/2011/004048.html)
114
115 * [Pieter Praet](https://notmuchmail.org/pipermail/notmuch/2011/004175.html)