Apache KeepAlive: Speed-up sluggish web pages

Is your web server working fine but always sluggish? Here's an important reminder: Check the KeepAlive directive in your httpd.conf file. Sometimes KeepAlives are off by default.

Prior to the development of web pages back in the early 90's, there was a web service called Gopher that was very popular. In those days, you would access a gopher page and read it - it was all text. There weren't any embedded documents in a gopher page. The idea was that you were accessing a page so that you could read it. If you wanted to access a related document, such as an image of some sort, you had to download that separately.

The web changed all that. Now a typical web page contains all kinds of media. In fact, if you check your server logs, you will find that there is a relationship between the number of Page Views you get on your site and the number of hits. Some sites have an average of 20 hits per page view while others have more or less. The web page itself is always the first document to load - but then it usually refers to many small images, some CSS files, some javascript files, some larger images, some video, etc. The browser makes a list of those references and starts loading them one-by-one.

Most of the referenced files will be on the same server that served the initial web page - so the browser will have to connect back again to the server to get them. This is where the KeepAlive directive comes in handy. If you turn it on the browser doesn't have to negotiate new connections for each of the subsequent files it needs to download. It can quickly get each file through the same connection that it used to get the first one - dramatically reducing the network and process overhead for the process.

Check your httpd.conf file for the KeepAlive directive. You might find that it's turned off by default in your distro.

Documentation on KeepAlive and related directives is here.

Tags: