Home > Hosting, Servers & Security >

Cure The Most Common Cause Of Dead Apache Servers (1)


02-28-2013 06:01 PM #1 caurmen (Administrator)
Cure The Most Common Cause Of Dead Apache Servers

Apache has a bad reputation: for being slow, for being bloated, and most importantly, for suddenly freezing or slowing to a crawl just when you need it most. Like, say, when you've just found a campaign with massive scaling potential.

I've heard a few people mention that they've had campaigns which seemed to be server-limited - whenever they increased the traffic beyond a certain amount, the campaign would just die. And it's quite likely that your server's configuration is the problem there.

But here's the good news - for Apache, in particular, there's one setting which is responsible for the vast majority of server crashes. It's very sensible in design, it looks very innocent - and if you go over a certain level of traffic, it'll kill your server stone-dead, with no warning.

Enter the villain: Keep-Alive.

How Keep-Alive Makes Your Server Dead

The Apache Keep-Alive setting stops your server from instantly dropping connections the moment they're finished. That's actually very sensible: otherwise, every time one of your visitors requests a file (and on an average landing page, they'll probably do that about 6 times), Apache has to start a new connection, which stresses your server's CPU out.

However, if your server gets hit by a mighty stream of traffic - like, say, you increasing the spend on your Facebook campaign - Apache's default KeepAlive of 5 seconds will proceed to quietly and efficiently murder your page load speeds.

Apache runs a fairly small number of connections at any one time - probably around 20 on a low-powered VPS. Assuming your landing page loads in .5 of a second, not counting DNS lookups and rendering time, Apache will send all that information out to the first person who clicks on your landing page - and then it'll keep that client alive for another 4 and a half seconds, doing precisely bugger-all. Meanwhile, more people are coming in - and once 20 of them have come in within a time of less than 5 seconds, all of Apache's connections are used up, and the next person to ask for a page gets put in a queue to be served once a connection is available.

If you've got, say, 10 people arriving a second, it's easy to see how this can go badly wrong. For the first two seconds, all's well - but in the third second, there are no connections available, and so the 10 people who clicked through have to wait 4 seconds for Apache to have free connections for them. By the fifth second, the wait's up to 7 seconds. And it just gets worse from there.

How To Fix The Problem

The simplest fix for this - and the one I'd recommend for most Apache setups - is to turn KeepAlive off.

This is very easy to do.



You're now back up and running with no KeepAlive - and hopefully, no more crashes.

When You May Want To Keep Keep-Alive Alive

If you're running a high-powered server (at least 2Gb of RAM) with a reasonably high MaxClients set ( ask your hosting company or check httpd.conf ) and you have a landing page with an unusually large number of images - say, a long-form page - you may be better to enable KeepAlive, but reduce its timeout.

By default, Apache2 sets the timeout to 5 seconds (15 on older versions) which is way, way too long. If you're in the situation above, I'd recommend changing the timeout to 1 second.

To do that, use the instructions above, but instead of looking for "KeepAlive On", look for "KeepAliveTimeout" and change the number after it from whatever crazy-ass setting it currently has to "1". You may also want to reduce MaxKeepAliveRequests at the same time - reduce it to the number of images, stylesheets and Javascript elements on your longest landing page.

And that's it! If you have questions, comments, suggestions or corrections, please do comment below!


Home > Hosting, Servers & Security >