Qmail Big concurrency

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

  1.  

__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...

php tail

The Problem

You want the functionality of tail(1) in a php function.

The Solution

Bellow is a php function that gives you the last N lines from a file. It doesn't do everything tail(1) does ( like following, retrying, etc ) but just the basic stuff:

  1.  

It may not be the fastest solution but it works.
Have a better one? Please let me know about it.

This week on twitter 2009-09-06

Powered by Twitter Tools

This week on twitter 2009-08-30

Powered by Twitter Tools

This week on twitter 2009-08-23

Powered by Twitter Tools

This week on twitter 2009-08-16

Powered by Twitter Tools

This week on twitter 2009-08-09

Powered by Twitter Tools

This week on twitter 2009-08-02

  • @mihaibrehar is that really Linus? not like a fake Jobs blog ? in reply to mihaibrehar #
  • spammers are everywhere... I just got a "follow" on backtype from someone following over 2k accounts with no comment #
  • @khelo cauti? in reply to khelo #
  • RT: @CommentLuv: dammit, Vista crashes when i listen to mp3's . I'm threatening it by downloading a linux iso #
  • my blog is my playground ... now playing with Twitterremote #
  • Sign into my TwitterRemote on http://twittercounter.com/mihaisecasiu so I know when you check my stats! #
  • Here's one feature I'd love to see in firefox: I click a link and it opens in new tab, when I close that tab firefox... http://ff.im/5VoPY #
  • @mihaibrehar but no love for FF 3.5 ๐Ÿ™ in reply to mihaibrehar #
  • friendfeed has a problem with email notifications on comments. Got an email notification 9 hours after the comment was posted #
  • @bobbyvoicu daca tot esti prieten cu Dragos, sa-i spui si ca banerele de pe site sunt mult prea enervante in reply to bobbyvoicu #

Powered by Twitter Tools.

Ask me questions

Have a question about unix, linux, freebsd.ร‚ย  Or maybe you want some advice about configuring apache, mysql,an email server like exim, qmail, postfix, a proxy server like squid cache or antinat, dns or anything else similar. Want some help with php programming or maybe you want to create a wordpress plugin?

Feel free to ask and I'll do my best to answer it on this blog. I will publish a new blog post for each question and my answer.

You can use the contact form or ( if your question is short enough ) you can send it to me over twitter

You can follow me on twitter or subscribe to my RSS feeds if you want to be notified when I post the answer to your question.

This week on twitter 2009-07-26

Powered by Twitter Tools.