Wanna send messages faster with your qmail server? Everyone will tell you to increase the remote concurrency. Till you find out that it can only go as high as 255. If you want more then that you have to apply the big concurrency patch
The Problem
Applying the patch and setting concurrency ( conf-spawn ) bigger then 509 will break the compilation. I was hoping to get at least 1000 on that new quad core 🙁
Why 509? It seems the number depends on the maximum size of the FD_SET array used for "monitoring" ( using select ) the file descriptors ( connection sockets or opened files ) . This limit is set in FD_SETSIZE constant to 1024. In case you're wondering ... the formula that gets you from 1024 to 509 is (FD_SETSIZE-5)/2 ( from chkspawn.c )
Trying to define FD_SETSIZE to a higher value in conf-cc like this -DFD_SETSIZE=4096 doesn't work because FD_SETSIZE is redefined in sys/select.h like this
#define FD_SETSIZE __FD_SETSIZE
__FD_SETSIZE is defined somewhere in /usr/include/bits/types.h ( actually typesizes.h ) to 1024. Defining -D__FD_SETSIZE doesn't work either...I even tried both and still no luck.
The Solution
After hours of digging through mail archives and sites I found this mailing list post that really helped:
Re: fd_setsize
If you just want to get it working just download my patch [download id="14"] , apply it ( after you apply the big concurrency patch ) , set conf-spawn to something big ( but less then 65000 ) and then you should be able to compile qmail.
If you want to know how it's done, read bellow...
It seems like the solution is to include bits/types.h, undefine __FD_SETSIZE and then define it to a higher value. The author of that post says that this is not a good idea (from the portability point of view, but I don't care about that ) since programs should never directly include bits/types.h ( true ) but the alternative is to modify that system file, again not a good idea since it will be overwritten by a possible update.
My first idea was to just use that code from the mailing list post into the select.h2 , since this is the file used to generate select.h and select.h is included in spawn.c and ckhspawn.c but this didn't work because spawn.c was including "select.h" after "sys/types.h" so even if select.h would define __FD_SETSIZE it would be useless since FD_SETSIZE ( this is the one that really matters ) would have been already defined in sys/types.h .
The solution I found at the time was to just move "select.h" at the top of the file and remove "sys/types.h" since it was already included from select.h but now I realized I could have just as well undefined and defined FD_SETSIZE too inside select.h
And that's the story about how I got to run 1000 concurrent connection in qmail.
The real problem
Now that we can have so much concurrency we hit another wall. Qmail, as most other MTAs, doesn't have any way of controlling the remote concurrency per destination domain.
At 1000 simultaneous connections it's very likely that it would create a few tens or hundreds of connections simultaneously to the same domain.
When this happens that domain will just ban your ip. So how do we fix this one?
PS: I have an answer but I want to see what you have for a solution 🙂 so hit the comments...
Hi,
I have similar problem too,
but I am useing big-concurrency patch, after modify /usr/include/bits/typesizes.h by hands I can compile qmail with conf-spam higher than 1000.
but real problem is qmail-send log show me
@400000004ac9b7d2072aa204 status: local 0/100 remote 513/600
@400000004ac9b7d2072df97c delivery 645: deferral: qmail-spawn_unable_to_create_pipe._(#4.3.0)/
Did you have the same problem ?
Any idea will help
Thanks
Harry
you have to increase the open files limit.
I do this in the script that starts qmail right before it starts it.
ulimit -n 5000 should be more then enough for 1000 concurrent connections but I use ulimit -n 10000
just in case I increase the concurrency limit later and forget to increase the limit too 🙂