Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

So I have Postfix + saslauthd + Courier-IMAP deployed on a Linode 1080 VPS. We are a small company, we have around 30 accounts (I use physical *nix users for the sake of convenience + Maildirs, see later), but we make extensive use of Courier's shared folders (for several accounts) feature with a custom script I wrote in Ruby. It filters emails through Spamassassin, reads a YAML file with some rules, then performs several checks to see where to file the email in our complex structure. Maildirs and phyiscal users gives me the flexibility I need for this.

Mail gets received, then gets passed to my script which is defined in the user's .forward file in its home directory.

All in all, that script takes about 2 seconds to finish. Now, we don't have an relatively high email volume (I estimate about 30-50 emails per hour) but I am looking for ways to speed this up, also ensure if our email load gets higher (or we catch a 'spam storm'), our server doesn't get suddenly hammered out of memory etc. My questions are:

  1. What is the way to filter emails thru the spamassassin daemon (instead of launching the app every every time mail is received) before it is passed to my script? Guess it is bad practice to do it the way I do now.
  2. Is there a way to limit how many emails postfix passes to my script at the same time? I don't want to end up having 10 instances of my script running at the same time.
  3. How could I make my script into a daemon? Would that makes things faster?

Thanks in advance.

P.S.: Emails (well, /home) are stored on a separate XFS partition mounted with noatime.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

What is the way to filter emails thru the spamassassin daemon (instead of launching the app every every time mail is received) before it is passed to my script? Guess it is bad practice to do it the way I do now.

Look at amavisd-new, which is written in perl. It will do what you're looking for, integrates at a network-level (should you desire) and provides antivirus scanning as well. Most of the major linux distros provide it as a pre-built package. The only thing you have to worry about is that some of the distros will use a stale version that has the occasional bug. Most of these bugs will cause amavis to wedge or terminate; so if it's, say, 3 versions older than what's at the offical site, I would seriously contemplate managing that one package by hand.

Is there a way to limit how many emails postfix passes to my script at the same time? I don't want to end up having 10 instances of my script running at the same time.

You're talking about rate limiting. Given the "small" size of the server, I would set the postfix rate limiter itself to something like 3-6 emails a minute, rather than set it on the scanning side. If you try to accept delivery on everything, a spam storm will simply clog your queues, and you'll end up with a backlog anyways.

How could I make my script into a daemon? Would that makes things faster?

Tons! I can't help you in this regard, but having your script pre-launched would cut out significant overhead.

share|improve this answer
    
"I would set the postfix rate limiter itself to something like 3-6 emails an hour" 3-6 per hour? huh? maybe I'm misunderstanding something... –  KTamas May 18 '09 at 19:43
    
(sigh) typos, gotta love 'em.... post is fixed. –  Avery Payne May 18 '09 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.