Tern vs Cyrus IMAP
Cyrus IMAP is the baseline Tern is measured against, and the server its first mailbox came from. The same mailbox was loaded into both: 403,757 messages in 32 folders, 11.3 GiB as received. This page says what was measured, how, and what the figures leave out.
Where they differ
| Cyrus IMAP | Tern | |
|---|---|---|
| A message on disk | One file, as it arrived | A compressed row for its skeleton and small parts; large parts apart, by the hash of their content |
| An attachment | Inside the message's file, encoded as it was sent | Decoded, compressed, kept once however many messages carry it |
| The search index | Xapian, built by squatter in a pass of its own | Lists of words in the store's own engine, written in the same batch as the message |
| The native protocol | IMAP | gRPC, mail.v1. IMAP is served beside it |
| Folders | Mailboxes: a message is in one | Labels: a message is in any number, and always in All mail |
| Rules for arriving mail | Sieve scripts | Rules, which a Sieve script is read into |
| Written in | C | Rust |
On disk
Cyrus 3.10.2 and Stalwart 1.2.1 were each loaded on a volume of their own and measured after they settled. Sizes are GiB as allocated; the ratio is to the 11.3 GiB loaded.
| Cyrus 3.10.2 | Stalwart 1.2.1 | Stalwart, no search index | Tern | |
|---|---|---|---|---|
| Message bodies | 12.0 | 7.4 | 7.4 | 3.2 + 0.9 |
| Metadata, index | 1.2 | 2.6 | 2.2 | 0.14 |
| Search index | 9.2 | in the store | none | in the index: 0.06 |
| Total | 22.3 | 10.1 | 9.7 | 4.2 |
| Ratio to the mail | 1.97 | 0.90 | 0.86 | 0.37 |
| Files | 403,907 | 423 | 319 | 31,280 |
- Cyrus keeps each message as a file as it arrived, so bodies are the mail and a little more. Its Xapian index is four fifths of the mail: 9.2 GiB.
- Stalwart stores bodies compressed and once each, and the rest in RocksDB.
- Tern takes messages apart: 3.2 GiB of large parts, decoded and once each, and 0.9 GiB of message rows. Its index, with the words of every body, is 0.14 GiB.
Tern is a little over a third of the mail, less than half of Stalwart's and under a fifth of Cyrus's. Most of the difference with Stalwart is probably base64: an attachment kept decoded is three quarters of what was sent, before compression and before it is kept once.
Not like for like. The search indexes of Cyrus and Stalwart do more than Tern's. Cyrus's holds where each word stands, for phrases, and both index headers. Tern's has the words of bodies and of subjects, and names; positions would add about 0.2 GiB. Tern has no replication and no backup copy yet. The Cyrus figures are from a second, reviewed run; the first had measured 26.8 GiB, with a search index of 13.6 GiB, and why that index was half as large again was not looked into.
Building the search index
| Cyrus IMAP | Tern | |
|---|---|---|
| Loading the mailbox | 37 min, by IMAP APPEND | 8 min 44 s, both at once |
| Indexing its words | 2 h 14 min, afterwards | |
| When new mail can be found by its words | Once the indexer has reached it | When the delivery is acknowledged |
Both on the same pool of three spinning disks, but not the same way: Cyrus was loaded one message a command while two Stalwart servers were being loaded beside it, with disk syncs turned off for the load; Tern was delivered in batches, with syncs, while the Cyrus server was paused, its large parts already in the blob store. Other machines share the disks. And 2 h 14 min is the first build of a whole mailbox's index: a Cyrus in service indexes new mail in the background as it arrives. The figures say what each took here, and little more.
On the wire
The larger difference is not in any one command. It is in how many a screen needs. A mail API in front of Cyrus pays for IMAP's shape in round trips; Tern's API was laid out from what the screens show.
| To show | Over IMAP, as a mail API backend does it | Tern, over gRPC |
|---|---|---|
| The folders with their counts | A LIST, then a STATUS for each folder: 33 commands for 32 folders | ListFolders: 1 call |
| A page of a folder | A SORT of the whole folder, then a FETCH of the page | ListConversations: 1 call |
| A search across folders | Up to a hundred EXAMINE and UID SORT pairs, again from the first folder for every page | Query: 1 call |
| A conversation | A search of every folder for the thread's Message-IDs | GetThread: 1 call |
| What changed since I was last here | A resynchronisation of each folder | Changes: 1 call for the whole mailbox |
Counts of commands, not timings: the two have not been timed against each other screen for screen. IMAP has extensions that fold some of these, LIST-STATUS among them, and Tern's own IMAP serves them. Cyrus also speaks JMAP, which was not measured here.
The same IMAP commands, to both
Tern serves IMAP too, so the same commands can be sent to both servers. The whole flow, median of 20 (10 for the heavier), in milliseconds.
| Flow | Tern | Cyrus |
|---|---|---|
Folder list: LIST, then STATUS of each of 32 | 3.5 | 89 |
| Folder list in one command (LIST-STATUS) | 0.13 | 72 |
| Open the inbox (36,898 messages) | 14 | 7 |
A page of the inbox: open, STATUS, sort by arrival, fetch 50 | 26 | 33 |
| The same sorted by date sent | 46 | 33 |
| Ids of the inbox: sort all by date, 13 searches by flag | 102 | 124 |
| Search the inbox for a word of a subject, sorted | 109 | 230 |
| Resynchronise the inbox (QRESYNC), nothing changed | 20 | 8 |
A thread in the inbox: two HEADER searches | 88 | 469 |
| Open the largest folder (166,143) | 51 | 29 |
| A page of it, sorted by date sent | 183 | 159 |
| Ids of it: sort all by date, 13 searches by flag | 324 | 586 |
| Search it for a word of a subject, sorted | 606 | 1,094 |
| Resynchronise it, nothing changed | 40 | 29 |
| One message, whole | 0.26 | 34 |
| Flags of every message of the inbox | 194 | 49 |
Read this table with care. The two columns are not from the same machine. Tern was on NVMe on the development machine, its store read from memory; Cyrus was on the benchmark machine's spinning disks, reached through a tunnel that adds 0.4 ms a command, while it was still building its search index. Cyrus's column shows where Tern stands, no more. The copy on Cyrus also had no flags set, which the rows that search and fetch flags should be read with. Tern's own figures on those spinning disks are on the storage page.
Where Cyrus is ahead in it, the reason is the layout. Tern keeps flags by message and not by folder, so the flags of a folder that is a tenth of the mailbox are read from among ten times as many. Why opening a folder and resynchronising it take Tern about twice as long has not been looked into.
The same answers
With the same mailbox in both, every message's ENVELOPE and BODYSTRUCTURE was asked of each server and compared. Flags could not be: the copy on Cyrus had none.
| The same | Differ | |
|---|---|---|
| Structures | 403,742 | 15 |
| Envelopes | 403,457 | 300 |
What differs is mail that breaks the standard, which the two read differently: address lists with brackets around the whole list, names with an @ and no quotes, eight attached messages sent base64-encoded, a few multiparts whose type Cyrus does not take for one.
Tern's IMAP also passes a program of 100 checks written with JavaMail 1.6.8 (folders with names outside ASCII, append, STATUS, SORT, searches, flags and keywords, copy and move, quota, resynchronising, IDLE), and Dovecot's imaptest with ten clients at once reports nothing in its plain stress run.
Moving a mailbox from Cyrus
cyrus-migrate reads a Cyrus spool as it lies on disk and appends its mail to Tern through the API. Cyrus's files are only read.
- What it reads: index files of versions 12 to 20 (the trial met 12, 13 and 17),
cyrus.header, flags and keywords, quota, the active Sieve script, and the memory of vacation replies indeliver.db. - What becomes of it: folders become labels, a message that Cyrus holds in two folders becomes one message with two labels, and the Sieve script becomes the person's rules. With the vacation memory brought over, nobody who got a vacation reply from Cyrus gets another too soon; that part is tested on files a Cyrus wrote, and was not used in the trial below.
- It can be run again. Each message carries its Cyrus GUID as its key, so a message sent twice is stored once. A run that was cut off is simply started again.
verifycompares what Tern holds with the spool: missing and extra messages, labels, flags, arrival times, the script, the quota, and the bytes of every message.- What it does not bring: IMAP's UIDs and UIDVALIDITY, so IMAP clients download the mailbox again; subscriptions and special-use folders; shared folders and their rights.
| First run | Second run | verify | |
|---|---|---|---|
| Wall time | 1 h 54 min | 1.5 s | 132.7 s |
| Peak memory | 599 MiB | 610 MiB | 639 MiB |
| Messages appended | 403,911 | 0 | |
| Refused: file unreadable | 1 | 1 | |
| Missing; extra, labels, flags, bytes, arrivals, script, quota | 1; all 0 |
The one refused and the one missing are the same message: its index record is live, and its file is not in the copy. The store afterwards took 4.87 GB; the 13.3 GB of Cyrus's files include 2,124 expunged messages not yet cleaned up.
The first run made 59 messages a second, far below what appending alone does on generated mail (236 a second on one stream). The likely cause, not yet proven, is the migrator's own state file, which records each message in a transaction of its own. Batching that is not built.
Where Cyrus is ahead
Cyrus has carried mail for decades, and Tern is not released. Beyond that:
- Replication, and many servers acting as one.
- Shared folders, with rights on them between users.
- Phrases answered from the search index, which keeps where each word stands.
- JMAP, and calendars and contacts.
- Fetching flags and headers of a whole folder at once, as the table above shows.