Optimizing SMTP Throughput

The below items highlight the different ways to improve throughput when sending outbound messages through the SocketLabs On-Demand service. 

  • Send multiple messages per connection.
    • Each time your software opens & closes a new connection there is a lot of processing overhead. In addition to the connection overhead itself your application must also authenticate for each connection, which requires several round trips. Sending one outbound message after the other on the same connection will bypass a lot of this overhead.

 For optimal performance, please limit the number of messages per connection to 50.

  • Create multiple connections.
    • The SocketLabs server allows up to 20 simultaneous connections per account so you should use all 20 in order to inject outbound messages as fast as possible. Since SMTP has a lot of back and forth protocol traffic each side spends time waiting for responses. With multiple connections you are able to have some connections sending while others are waiting, which helps maximize throughput.
  • Use command pipelining.
    • SMTP pipelining allows commands to be sent and received in batches which cuts down the back and forth traffic and will speed your per-message rate.
 

Alternative to Making Changes to the Mailing Software

If you do not have the ability to make the above changes to your software or you are using a 3rd party application to generate your outbound emails we recommend installing a local relay server that will do all this for you. There are many free SMTP servers out there. The two major ones are Sendmail and Microsoft SMTP service. Both of these have already implemented the above technologies and can be used as a smart host to relay outbound mail to our server. Since a local SMTP server will not have the back-and-force latency of sending across the internet, your application should not have performance problems when relaying to your local server. The local server will then be able to automatically optimize connections to get the best throughput.

Here are tips you can use to setup a local SMTP server:

  • Postfix is a great alternative that is installed on many Linux distributions by default or is installed when configuring for outbound email via tasksel --section server on some Ubuntu and Debian builds. It's very simple to set up smarthost relaying with authentication on Postfix as compared to Sendmail. The example here is based on the default tasksel installation mentioned above, with a user already signed in with elevated privileges (i.e. by typing sudo su), with your SocketLabs account using the following credentials:
    • Server: smtp.socketlabs.com
    • User: SMTPUsername
    • Password: SMTPPassword
  1. Create a passwords file:
    cd /etc/postfix
    vi relay_auth
  2. Give it the following contents:
    smtp.socketlabs.com SMTPUsername:SMTPPassword
    [smtp.socketlabs.com]:2525 SMTPUsername:SMTPPassword
  3. Set permissions and build hash:
    chown root:root relay_auth
    chmod 600 relay_auth
    postmap relay_auth
  4. Configure Postfix Main Config:
    vi main.cf
  5. Make sure this is part of its contents: (you may just have the smarthost listed when you open it if you added that during the tasksel function):

    relayhost = [smtp.socketlabs.com]:2525
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/relay_auth
    • We've used the server on port 2525 here because many ISPs block port 25. If you do want to use 25, remove the port and the brackets for the relayhost.
  6. Restart Postfix:

    /etc/init.d/postfix restart