-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
storage: remove 500 ms debounce on IMAP IDLE notifications #216
base: main
Are you sure you want to change the base?
Conversation
This commit removes hardcoded 500 ms debounce from storage that delays all storage notification subscribers such as IDLE and NOTIFY commands. 500 ms debounce constant NOTIFY_DELAY_MSECS was added in 2009 [1]. Before that Dovecot was only delivering notifications when a second-resolution timer is changed by at least 1, so IDLE notifications were delayed by half a second on average. [1] dovecot@56fb5d0
I have made a patch that actually deletes 500 ms delay I then looked into Then I thought about the issue again So unless there is an IMAP client See related issue at chatmail/server#72 for the "chatmail" Postfix+Dovecot setup that needs reduced delay for chatting. |
This is now deployed on https://c20.testrun.org/ account and works without problems. |
The worry I have related to performance isn't about IMAP client behavior, but rather Dovecot's mailbox_sync() calls. With no delay IDLEing imap process would call mailbox_sync() every time there is a write to dovecot.index.log, whatever that reason is. If another sync is already running by another process, it would wait a bit for the exclusive lock, but otherwise it would be syncing as rapidly as there are .log file writes. Although syncing isn't necessarily expensive, it's not trivially cheap either. So this might increase the server's CPU usage. I'm not sure if that's more of a theoretical problem, but over the years I've grown to be wary of performance regressions, since they sometimes pop up rather unexpectedly. |
Without measuring I also cannot tell An option that was discussed in the mailing list I have another proposal. If nothing else works, |
If anyone wants to try this out, we are hosting this PR as a .deb build on https://build.opensuse.org/package/show/home:deltachat/dovecot so it is easy to install |
@sirainen with respect to the CPU concern in 2009 I believe this would be cause to reject the merge; cost is a real factor at scale. In 2025 I dont believe its a concern. The smallest mailserver is still equipped with 4-8 CPU cores. Scalable IMAP servers are all wildly more performant than this however. Epyc or Intel, I think the concern is moot |
I've asked for this change in debian's experimental repository, and the maintainer there is looking for more feedback from upstream on this change. It would be great to understand if this patch is under consideration. Thanks for dovecot, it has been a dependable workhorse for me for years! |
It's not exactly a delay, but a debounce, so if two IDLE notifications arrive within 500 ms, callback is called only once. This does not happen normally, maybe if you move a lot of messages from one folder to another or use https://imapsync.lamiral.info/ while having a client open, but then that's it, you will get an IDLE interruption on every message rather than every 500 ms, it's anyway should not be more expensive than actually writing a mail to the folder. On a chatmail server which delivers around 3-5 mails per second (with deduplication etc., so some of these mails are hardlinks, but still) this does not cause any problems so far. |
How about something like this, which starts with 0 delay but increases it for a while and periodically resets it back to 0? Could still be tweaked a bit I guess, but I'd think this would work well enough for your use case while guaranteeing that there's no huge flooding of the notify callback:
|
@sirainen This approach has a non-continuous behavior that is not easy to analyze: if email arrives exactly every 10.1 ms then there is no delay, but if email arrives every 9.9 ms, it will be delayed by half a second eventually. Having a sudden change in resource usage when the load crosses 1 message per 10 ms threshold looks strange. In the case you want to keep debouncing, I'd go for GCRA (leaky bucket) ratelimiting, say allow 1 notification per 500 ms, but with a burst of 5 notifications. Then if you have a continuous stream of messages from e.g. imapsync, it immediately causes 5 notifications and then one notification per 500 ms, while for normal email usage (or chatting over email) there are no delays ever. If you increase the rate of incoming messages from 0 to 2 messages per second, the rate of notifications grows linearly, then stays at 2 notifications per second. |
This commit removes hardcoded 500 ms debounce
from storage that delays all storage notification subscribers such as IDLE and NOTIFY commands.
500 ms debounce constant NOTIFY_DELAY_MSECS
was added in 2009 [1]. Before that Dovecot
was only delivering notifications
when a second-resolution timer
is changed by at least 1, so IDLE notifications
were delayed by half a second on average.
[1] 56fb5d0