KeepAlive Directive Explained

  • Avinash
  • 0
  • Aug 28, 2011
  • Web Server

KeepAlive Directive is used to enables the HTTP Persistence connections.

This is the persistance connection features of HTTP/1.1 which provides the long lived HTTP session which can be sent over same TCP connection.

Using KeepAlive is closely related to the MaxClients setting.

Note: In some cases 50% improvement in latency time for HTML document with more images.

Syntax for KeepAlive

KeepAlive On|Off
KeepAlive On|Off

Default value for KeepAlive

KeepAlive On
KeepAlive On

How to enable KeepAlive?

KeepAlive On
KeepAlive On

Note: A Keep-Alive connection with HTTP/1.0 can only be used if length of the content known in advance.

How it works?

Basically KeepAlive keeps each HTTP connection open for short time to receive the follow up request from the same connection. This is because we can consider that client will try to make a several connection to our web server as a follow up request. So we can enable the KeepAlive Directive to restrict client to make different connection for every request.

So if you have a lots of traffic on your website then in some cases it will create a problen by enabling the KeepAlive. This is becuase we will have lots of unused open connection to our web server.

So how to overcome from this problem?

Here is the solution for this. We can set the KeepAliveTimeout for the cache HTTP connection. So let’s see how to set the KeepAliveTimeout.

# Enaling the KeepAlive Connection KeepAlive On # But for just 2 secs KeepAliveTimeout 2
# Enaling the KeepAlive Connection
KeepAlive On
# But for just 2 secs
KeepAliveTimeout 2

Now webserver will cache that HTTP connection for just 2 secs so we will not have unrequired open connections.

Limit the number for Persistance Connections

Here we can set the how many number of requests to act as a Persistance Connection. MaxKeepAliveRequests is used for this.

How to Set it?

MaxKeepAliveRequests 100
MaxKeepAliveRequests 100

If this value is set to 0 then it will be considered as a unlimited numbers of requests.

Note: It is recommended to set the higher value of this Directive for higher performance.

Conclusion

It is recommended to enable the KeepAlive Directory but with some amount of KeepAliveTimeout.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: