The problem happened again this morning. Removing fsync calls helped, but I'm not sure about leaving that enabled long term.
I still believe the problem is multiple dovecot processes trying to write to a single folder at the same time. (If I could run dtrace I might be able to cobble together a script to prove it.)
I tried writing a sieve script to direct the messages to a set of folders, but I'm not able to make the logic work. I was thinking something like: generate random # ($N) between say 1-10, then file message into folder mail$N. But I didn't find a method to do that within sieve.
My next thought was to try parsing the message-id header. If the first character is [0-5] then fileinto mail1, etc. Then I could go so far as having 36 subfolders which the messages could be written too. This mailbox only keeps messages for a rolling 1d window. Right now for example it has 260,186 messages in the INBOX.
The sieve script I tried (with only about 4 hours of sleep) was
require ["fileinto","regex"];
if header :regex "message-id" "^1" { fileinto "mail1"; } else { keep; }
If anyone has some suggestions on how I might spread the messages out over multiple folders I'd like to hear your thoughts. Again the servers are configured using maildir, so each folder should have its own index and thus file locking contention should be less, at least so goes the theory in my head.
Thank you, Chad