Skip to content

500 ms delay between sending a message over SMTP and getting IDLE notifiedΒ #72

Closed
@link2xt

Description

@link2xt

I have measured round trip time sending messages between two accounts: chatmail/core#4974 (comment)

It takes roughly 1.1 seconds to send a message to the echo bot and receive a reply with two Delta Chat accounts. Slightly more than 0.5 seconds (516 or 517 ms) is spent between a mail is sent over SMTP and Dovecot notifies the client in IDLE mode that the message has arrived.

There is a suspicious constant #define NOTIFY_DELAY_MSECS 500 in Dovecot mailbox-watch.c:
https://github.com/dovecot/core/blob/93a53a9d590f0220de28600f36a969cc38c3148b/src/lib-storage/mailbox-watch.c#L12

mailbox_watch_add is called from storage implementation. We are using Maildir (may consider switching to dbox, but Maildir is good enough), so in our case it is here:
https://github.com/dovecot/core/blob/93a53a9d590f0220de28600f36a969cc38c3148b/src/lib-storage/index/maildir/maildir-storage.c#L632-L645

Here is a mailbox_notify_changes which dynamically dispatches to a particular storage implementation:
https://github.com/dovecot/core/blob/93a53a9d590f0220de28600f36a969cc38c3148b/src/lib-storage/mail-storage.c#L2473-L2484

And finally, here is IMAP IDLE command implementation using mailbox_notify_changes to subscribe for notifications:
https://github.com/dovecot/core/blob/93a53a9d590f0220de28600f36a969cc38c3148b/src/imap/cmd-idle.c#L289

So it seems NOTIFY_DELAY_MSECS 500 directly affects how IDLE callback is called when storage notices changes. And it corresponds with the measurements, it is always slightly more than 500 ms delay.

And here is a commit adding it 14 years ago:
dovecot/core@56fb5d0

It reads:

mailbox_notify_changes(): Delay sending notifications for 500 msecs.

If the notification is done immediately, IDLE may not notice the change
because it's not finished yet.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions