Long Keepalives considered harmful

Long Keepalives considered harmful

by Martín Langhoff -
Number of replies: 8
We had some high load recently on the NZ cluster (it actually looked like a mini DoS from a misconfigured proxy or something). It made me look into our configuration and how "busy" our servers were.

Indeed, Apache's error log was filled with suggestions to raise MaxClients, as MaxClients is strictly bound to the memory we have on each server so as to avoid touching swap.

What I found was that Apache's default keepalives are 15 seconds. Ouch! Looking at /server-status showed a whole lot of Ks. Behind each of those Ks, there is an Apache process, holding on to ~15MB RAM each, waiting up to 15s for a client to make a new request.

In real life, however, browsers will give you a series of requests over a keepalive session, all back to back (fetch the webpage, images, css, etc). Once the page is loaded, it only makes another request when the user clicks on a link or form action -- definitely longer than 15s, and in that gap that process can serve several other users...

Instead, it will by default stay there for 15s until it declares the conversation over. Waaaaay to long to be there, hogging all that RAM, while other client machines want to talk to us.

In other words, if a browser is going to ask anything else, it'll do it within a second or two, or in a few minutes.

I lowered our keepalives to 2 seconds. It immediately freed up about half the processes. That means we can service about double the end-users with the same amount of RAM. big grin

Yummy!
Average of ratings: -
In reply to Martín Langhoff

Re: Long Keepalives considered harmful

by Scott Elliott -
Martin,

Thanks for the tip!  My server takes nowhere near the hits I'm sure you are getting though. smile  I'm guessing your tip would still be good for much less used systems?  Not being an apache guru, I am curious if there is a downside to moving the keepalives down to 2 seconds.

Also, is it KeepAliveTimeout 2 or KeepAlive 2?

Thanks again for all your tips on server tuning!

Scott
In reply to Scott Elliott

Re: Long Keepalives considered harmful

by Martín Langhoff -

I'd say there's not upside to long keepalives on a server running PHP. For a pure apache server (only serving static content, no mod_php or mod_perl loaded), the tradeoff makes a bit more sense, as only a few K are used by each child.

I use:

    KeepAlive On
    KeepAliveTimeout 2

big grin

In reply to Martín Langhoff

Re: Long Keepalives considered harmful

by Scott Elliott -
Great!

I'm running a pure apache server so I'll make a change and see what happens.  I'm guessing with my low load I won't see a difference, but I'll be expecting a much higher load next semester and this little fix may keep me out of trouble when my server gets more activity.

Also, I know your contributions to this forum (and many others) have helped this community greatly.  Thanks for your work in the community!

Scott
In reply to Scott Elliott

Re: Long Keepalives considered harmful

by Martín Langhoff -
Hi Scott! No worries (blush)

I wanted to mention -- when I say "pure apache" I mean the apache webserver with no heavy modules loaded. That is -- one that cannot run Moodle. Your webserver can run moodle I am sure big grin
In reply to Martín Langhoff

Re: Long Keepalives considered harmful

by Richie Foreman -
Martin--

Good suggestion!  Student will start hitting our cluster soon, so this is definitely a good find to come across.

Thanks,

Richie Foreman
In reply to Martín Langhoff

Re: Long Keepalives considered harmful

by Ralph Patterson -
So adjusting the "keep alives" is an apache setting or a moodle setting? ... and where is this set?

Thanks.
In reply to Ralph Patterson

Re: Long Keepalives considered harmful

by Geoff King -
It's an apache setting. On my Ubuntu server the setting is in /etc/apache2/apache2.conf to be precise.
In reply to Ralph Patterson

Re: Long Keepalives considered harmful

by Hugo Martin C. V. -
That's an Apache setting. You will find it in httpd.conf, no matter where it is installed, you can find it like this:

# find / -name httpd.conf
OR
# find / | grep httpd.conf
OR
# updatedb ; locate httpd.conf