KeepAlive, On or Off?

sergioraw

New Member
Hello,
Which is better:
KeepAlive On
or
KeepAlive Off

?

and what is the difference between them?

Thanks KeepAlive On Read here: https://secure.wikimedia.org/wikiped...ent_connection

Personally, I have it Off in my server. Off is better to avoid high server load. There is no definitive recommendation. If someone tells you 'it is better to keep it off', they are wrong. If they tell you 'it is better to keep it on', they are wrong again.

KeepAlive, basically, allows your server to serve multiple requests on a single connection. Whether you are going to need to keep it OFF or ON, depends entirely on what your server is used for and what you need to deliver.

Say, for example, you have a webpage that has 25 images all on the same page along with content and stuff. You have (for simplicity's sake), 1,000 visitors hitting that web page at any given time. When a visitor hits that page, he'll download the page content and the 25 images. 1,000 visitors hitting the page at the same time will download an equivalent to 1,000 pages and 25,000 images.

How does Keep-Alive come into play?

If you have Keep-Alive turned on, each visitor will establish one connection to your server, and all requests will be served through that one connection. Thus, to download 26 elements from your server, only one connection will be used. Scale that to 1,000, and you will have only 1,000 connections open.

So, if you have Keep Alive turned off, each visitor will end up establishing as many connections as the number of elements it needs to download. That is to say, each connection will serve one request. So each visitor establishes 26 connections. Scale that, and you'll have 26,000 connections.

Now I obviously don't need to tell you which one, out of the above two scenarios, is optimal. But my illustration is not conclusive. You cannot apply that logic to every situation.

Say, you have a single web page. No images. You have 1,000 people hitting your webpage. Whether you have Keep Alive turned on or off, you'll be serving 1,000 connections, no more. HOWEVER, if you have Keep Alive turned ON and the Keep Alive timeout is set at the default (60 seconds, that's extremely high); every connection established to your server will be held on for 60 seconds before it times out and closes itself. This will eventually waste your server resources keeping connections open that you don't need.

So is KeepAlive better left off, or should it be turned on? The answer to that, depends entirely on the kind of website you run.

Personally, I have it switched off; I run an image host, so not every client that downloads an element from my site necessarily downloads tens others. I will, at any given time, have a majority of people downloading just one or two images from my site/server. I would have KeepAlive turned off to prevent keeping any needless connections open. OR, I could keep it on in the event that someone wants to download more than a few images, but with a very low timeout (say, 2 or 3 seconds) to rule out resource wastage due to unneeded open connections.

Then again, when you're serving thousands of requests every second, 2 or 3 seconds matter a lot! So yeah, I have it turned off
smile.gif


What you will do, depends on your site
wink.gif
Hello,
Thank you Lifetalk. Very detailed and great explanation.
Actually, I have searched about this on Google many times and didn't understand the actual function of KeepAlive.
Currently, it is On on my server, and after reading your reply I have realized that it is better to keep it On for better performance.
Regarding timeout, I think that mine is 5, I'll try to decrease it to 2 or 3 as you said.


Thank you again. As I mentioned, 2 or 3 would be an optimal timeout value for a very busy site. If your site is not very busy, a timeout value of 5 seconds is just fine!
 
Top