Apache Directive - KeepAlive and KeepAliveTimeout

I run a very busy web server, my load averages are high and I'm looking at ways to reduce the load. Reducing the load is my primary aim, I don't care about anything else.

I have several questions about Apache's KeepAlive and KeepAliveTimeout directive. I understand what they do but I'm not clear on the following:

1. To reduce load on a very busy web server, would it be prudent to disable KeepAlive? Please explain why.

2. My MaxClients is set to 200, if KeepAlive was enabled then what KeepAlive setting would be reasonable (e.g. 1-2 sec or much longer?) to reduce load on a very busy web server?

2. My MaxClients is set to 200, if KeepAlive was enabled then what KeepAliveTimeout setting would be reasonable (e.g. 20-30 or much higher?) to reduce load on a very busy web server?

Apache's manual is vague and other websites have no information for tuning Apache's KeepAlive directive for very busy web servers. Please help.

Thank you.
topwizAsked:
Who is Participating?
 
ahoffmannConnect With a Mentor Commented:
if you really have a heavy loaded server **and** your hardware is not good enough for this, then you should probably switch KeepAlive off
AFAIK clients will not see a big disadvaantage 'cause the server is already slow (as you said). But with this setting you get a better performing server.
Does this answer your question?
1
 
samriCommented:
Hi topwiz,

It's pretty much hard to kinda say that, for busy server, you would need to have this settting.

Depending on your version of Apache (againg apache website);
1.3.x : http://httpd.apache.org/docs-2.0/misc/perf-tuning.html
Apahe2:http://httpd.apache.org/docs/misc/perf-tuning.html

Overall, it was about the machine where Apache is running.  OS might need to be tuned for optimum - look at max file descriptors, any other application is running - DNS, Sendmail, VirusScanner, Firewall, etc.
You might need to tweak some TCP/IP stack configuraion (beyond my knowledge really) - 10 or 100mbps, full/half duplex, etc.

On apache itself, in addition to KeepAlive/KeepAliveTimeout, loading of modules, directives, would make a difference.  General tips, try to use directive only if you need them.  Load modules only if you need them.  Someone told me, mod_rewrite, would tax some server performance. etc.

On apache itself, you could you mod_status (http://httpd.apache.org/docs-2.0/mod/mod_status.html) to monitor your server activity realtime.

I just couldn't find a better way than mentioning this again (even if you had visited it a number of times).
http://httpd.apache.org/docs/mod/core.html#keepalive
This directive is taking "on"/"off" as parameter.  In simple term - whether you want to use the feature or not.  For example, once you visit a site (www.someting.com), there would be a number of connection from your machine to the remote machine (on port 80).  Once the browse finished fetcing pages, the socket will be closed (if KeepAlive off).  If you click on a link on that page, another connection will be initiated.  Remember that opening/closing socket will require some overhead from OS, and Apache itself (same thing with closing the sockets).

Good thing here is, you might not need to have a big number of StartServers/MinSparesServer/MaxSpareServer, which is good (since each of the Apache child process would be eating up RAM too), but, remember the overhead to open and close the sockets.


http://httpd.apache.org/docs/mod/core.html#keepalivetimeout

KeepAliveTimeout will determin howlog a persistent connection will be kept open.  Having a big figure would cause existing connection remains open, for subsuquent erquest.  REmember that apache would fork a child process to server a request.  If a user (clint) visit a page with 3 graphics -- there would be 4 apache child process to serve this request.  If the KeepAliveTime is kept big, new request would cause a few more child to be spawned (started) -- remember the overhead!

However, if we keep the KeepAliveTimeout to a low value - it will cause the existing connection to be closed fast -- good so that apache could fork a new chile to serve incoming request.  However, if the request is coming from the same remote client, it will not be very good, since we might as weel keep the recent connection open (high keepalivetimeout), rather that starting to initiate another connection -- remember the overhead again.

Overall, you would need to experiment the figures a bit.


Note: Setting KeepAliveTimeout to a high value may cause performance problems in heavily loaded servers. The higher the timeout, the more server processes will be kept occupied waiting on connections with idle clients.

cheers.
0
 
topwizAuthor Commented:
Samri,

Thanks for your reply. I'm running Apache version 1.3.x. I've read all of Apache's manuals and I've optimized everything by the book. I'm well aware of the other factors that you've mentioned.

The bottom line: my specific questions about KeepAlive and KeepAliveTimeout is still NOT answered.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
topwizAuthor Commented:
ahoffmann,

Basically that does answer my question. However, do you have any facts (e.g. reputable websites) to backup your comment?
0
 
ahoffmannCommented:
no reputations, try&error as samri already suggested
AFAIK, most docs will tell you to upgrade your hardware ('cause it might be cheaper and simpler than tweaking software)
0
 
samriCommented:
topwiz,

what is your machine spec anyway?  hardware (cpu/RAM), OS.

From my experience, the apps, will depend too much on hw/OS performance.

bandwith will be another issue to look at.

if you happens to be running try monitoring you machine using "top".  It would give you some indication of what is happening.  Remember that, is most cases, RAM would play a big role, since when your machine starts to run out of physical RAM, it will start to swap to disk (paging).  When this happens, IO will be the bottlneck -- and will start to cause CPU utilization to jump -- it's all like a chain reaction.

I personally do not have much expertise in performance fine-tuning, but those items would be some basic that you might want to look at.

hope this would give some idea.

cheers.
0
 
ag0nyCommented:
1) Make sure that HostNameLookups is set to 'Off' in your httpd.conf. The IPs of your visitors will not be resolved, so each httpd process will process the requests faster. This will result in fewer httpd processes running concurrently and probably a big improvement in performante (if HostNameLookups was set to 'On' previously).

2) Strip your binaries. Go to your Apache bin/ directory and do an 'strip *' there. Strip the loadable modules too (in Apache's libexec/ directory). This will remove unused symbols from the binaries and make them smaller, resulting in a speed improvement when httpd processes are forking.

3) Make sure that you're not running low on memory. As soon as your system runs out of RAM and starts using swap, it will start crawling because disk access is sooo much slower than RAM. If this is your case, just adding more memory will make your system much faster, without changing anything else. If you're on Linux, run 'free' to see how much memory/swap you're using.

4) Remove all the modules that you're not using. Many distributions come by default with lots of modules compiled in the httpd binary. Compile from scratch adding only the modules you need. Or if you're not sure about what modules you're using, compile only with module 'so' (--enable-module=so) and the rest of modules as dynamic (--enable-shared=<modulename>). If you do this, Apache will load only the modules that are used (on a on-demand basis), so memory usage will improve too.
0
All Courses

From novice to tech pro — start learning today.