Performance tips for Sendmail
Posted: Wed Aug 08, 2007 8:32 pm
Before I begin, I suggest that you purchase O’Reilly’s sendmail 3rd editon by Bryan Costales and read chapter 6 from cover to cover. It is there were I learned this tip, and there are likely many other important tips in there that I did not implement or understand.
Firstly, I found an important change that I made to improve performance was to define two queues, one for sending with very fast (low) time-out values and a second queue with the conservative time-outs (5 minutes is default for OpenSUSE 10.2).
The reason is that what I found were there were many slow mail servers which while doing reverse lookups and other spam related testing, took some time to response to my HELO. These slow servers were causing sendmail to spawn new sendmail instances which in turn caused a much higher memory usage. By defining two queues called sendmail-fast and sendmail-normal I added 50% more emails per hour! (mileage would depend on the quality of the email servers in your list)
Here is how I did it.
Firstly, there is a file in /etc/mail called linux.mc. I made a copy of that file and called it linux-fastqueue.mc. To the bottom of the linux-fastqueue.mc file, I added these lines:
Then I saved the file.
I compiled the file with this command:
which creates another configuration file in the /etc directory.
Next, I modified this file:
And changed these lines:
To this:
This defines two mail queues, one called sendmail-normal which has the standard definitions as defined in sendmail.cf and a second called sendmail-fast which uses the new settings. This also causes fast to create new instances every minute while creating the other instances every 5 minutes.
The effect of this change is that the fast configuration will time-out any SMTP server which doesn’t quickly answer. Later, the –normal version will pick it up and process with the 5 minute timeouts.
I am sure there are improvements to be made, and I am experimenting with QueueSortOrder=random for the fast queue to speed up initial queue scans. I wanted to share this information now so that others could benefit from my experimentation.
Firstly, I found an important change that I made to improve performance was to define two queues, one for sending with very fast (low) time-out values and a second queue with the conservative time-outs (5 minutes is default for OpenSUSE 10.2).
The reason is that what I found were there were many slow mail servers which while doing reverse lookups and other spam related testing, took some time to response to my HELO. These slow servers were causing sendmail to spawn new sendmail instances which in turn caused a much higher memory usage. By defining two queues called sendmail-fast and sendmail-normal I added 50% more emails per hour! (mileage would depend on the quality of the email servers in your list)
Here is how I did it.
Firstly, there is a file in /etc/mail called linux.mc. I made a copy of that file and called it linux-fastqueue.mc. To the bottom of the linux-fastqueue.mc file, I added these lines:
Code: Select all
dnl TMG: Added to set this queue to only wait for 4 seconds for a response.
define(`TO', `4s')dnl
define(`confTO_ICONNECT', `TO')dnl
define(`confTO_CONNECT', `TO')dnl
define(`confTO_COMMAND', `TO')dnl
define(`confTO_DATAINIT', `TO')dnl
define(`confTO_HELO', `TO')dnl
define(`confTO_HOSTSTATUS', `TO')dnl
define(`confTO_INITIAL', `TO')dnl
define(`confTO_MAIL', `TO')dnl
define(`confTO_QUIT', `TO')dnl
define(`confTO_RCPT', `TO')dnl
define(`confTO_RESOLVER_RETRANS', `TO')dnl
define(`confTO_RESOLVER_RETRY', `TO')dnl
define(`confTO_RSET', `TO')dnl
define(`confTO_DATABLOCK', `TO')dnl
define(`confTO_DATAFINAL', `TO')dnl
I compiled the file with this command:
Code: Select all
m4 linux-fastqueue.mc > /etc/sendmail-fastqueue.cf
Next, I modified this file:
Code: Select all
/home/openemm/bin/mailer.sh
Code: Select all
mproceed "mail queue"
$sm -q1m -NNEVER -OQueueDirectory=$BASE/var/spool/QUEUE -OPidFile=/var/run/sendmail-openemm-queue.pid
Code: Select all
mproceed "mail queue"
$sm -q5m -L sendmail-normal -C /etc/sendmail.cf -NNEVER -OQueueDirectory=$BASE/var/spool/QUEUE -OPidFile=/var/run/sendmail-openemm-queue.pid
$sm -q1m -L sendmail-fast -C /etc/sendmail_fastqueue.cf -NNEVER -OQueueDirectory=$BASE/var/spool/QUEUE -OPidFile=/var/run/sendmail-openemm-queue-fast.pid
The effect of this change is that the fast configuration will time-out any SMTP server which doesn’t quickly answer. Later, the –normal version will pick it up and process with the 5 minute timeouts.
I am sure there are improvements to be made, and I am experimenting with QueueSortOrder=random for the fast queue to speed up initial queue scans. I wanted to share this information now so that others could benefit from my experimentation.