Manage Mail Server Connections

September 9, 2010 Performance

One aspect of managing mail server connections is managing Keep-Alives.  Managing Keep-Alives with TCP connections may increase reliability of connections or save resources on the server.

Once a connection is made with a mail server, the TCP protocol does not determine that data must be exchanged in order to maintain the connection.  It is possible for a connection to remain open for a long period of time without exchanging data.  Keep-Alive helps the server determine if the connection is no longer available as there is no point in maintaining resources if the connection is not available.

Resource Management
Here is an example of a client connected to a mail server.  Note how many connections are made to the secure IMAP.  Depending upon how many folders in your IMAP account and depending on how many accounts, you will have multiple connections to manage.

tcp        0      0 192.168.3.4:49215     192.168.3.69:993        ESTABLISHED
tcp        0      0 192.168.3.4:49216     192.168.3.69:993        ESTABLISHED
tcp        0      0 192.168.3.4:44262     192.168.3.69:993        ESTABLISHED
tcp        0      0 192.168.3.4:44226     192.168.3.69:993        ESTABLISHED
tcp        0      0 192.168.3.4:44263     192.168.3.69:993        ESTABLISHED

The problem with so many connections to the mail server is  to manage resources for the mail server when you have a lot of  users and many connections.  Keep-Alives is one aspect of managing server resources.

By managing Keep-Alive settings you can either save resources that are being wasted or increase the Keep-Alive settings to insure more stable connections.

Keep-Alive Settings
There are three variables that refer to keep alives.
.
This setting is the interval between subsequential keepalive tests.  This setting occurs regardless of what is happening on the connection.
/proc/sys/net/ipv4/tcp_keepalive_intvl

This setting is the interval between the last data packet sent and the first keepalive test.  Once the connection is marked as keepalive, the counter is not used.  Note, ACKs are not going to be considered data.
/proc/sys/net/ipv4/tcp_keepalive_time

This setting is the number of unacknowledged tests to send before considering the connection dead and then notifiying the application layer.
/proc/sys/net/ipv4/tcp_keepalive_probes

Here are default settings.
cat /proc/sys/net/ipv4/tcp_keepalive_intvl
75
cat /proc/sys/net/ipv4/tcp_keepalive_time
7200
cat /proc/sys/net/ipv4/tcp_keepalive_probes
9

These settings allow for connection getting dropped after 2 hours and 11 seconds.  Adjusting these settings can allow for longer connection times or lesser connection times to save on system resources.

Changing Keep-Alive Settings
For testing purposes the best thing to do is to echo a setting the current setting.  This will go away on restart.  For example, if your connections were not as reliable as you needed, clients complained about dropped connections, then increase your Keep-Alive settings.

echo 15 > /proc/sys/net/ipv4/tcp_keepalive_probes

If you were more interested in saving resources on the mail server, then decrease the time for Keep-Alive.

echo 6000 > /proc/sys/net/ipv4/tcp_keepalive_time

Whatever you do test and listen to clients to verify your settings.

Tags: , ,

Comments are closed.