Web Hosting Talk







View Full Version : apache KeepAlive latency problem


vivhost
11-18-2004, 02:42 PM
Hello, I've been searching and reading about KeepAlive and a latency problem that I'm seeing on a box with apache 2.0.

From my tests, the smaller the KeepAliveTimeout value I use, the better performance I get (lower latency time). I'm measuring latency time with echoping on the local loopback.

This is a box with high-traffic and plenty of pages with 20 pictures or more on each page. So it's important to me that I find a setting which allows for low latency while still economizing system resources.

I'm using prefork model and these are the current settings:

<IfModule prefork.c>
StartServers 28
MinSpareServers 50
MaxSpareServers 100
MaxClients 256
ServerLimit 256
MaxRequestsPerChild 2000
</IfModule>

Here are some KA values I used, and the result:

KeepAliveTimeout 15 - results in high latency (8-15 seconds)
KeepAliveTimeout 5 - results in average latency (1-4 seconds)
KeepAlive Off - results in very low latency (<1 sec)

The other system variables are fine, CPU load is less than 10% average, memory/swap is fine.

My question is twofold. Why should KeepAlive cause such high latency when used with default value, and if this is the case, what will be the risk of running without KeepAlive?

I'm currently using KeepAlive with a low value for timeout, hoping that the latency cost is worth something.

The websites are running HTML only, very little PHP/mySQL usage otherwise (less than 1% of the traffic). The traffic is currently about 1.5 Mb/s.

Thanks for any thoughts you might have about this.

Jakiao
11-18-2004, 05:10 PM
KeepAlive, on a very active server, causes a LOT of spawned processes. This is why the latency gets very high for you. If you have a lot of people surving making a lot of hits, that is a lot of system resources in use. Thus, the latency rises as the server's resources drop.

I have a server which currently has about 450 active uses surfing the pages (an image gallery site). With KeepAlive on, our loads spike to 10 and over. With KeepAlive off, our loads are around 0.90 at average usage.

If you get a substantial amount of connections, KeepAlive off will always help you. KeepAlive is meant for servers not running as many connections, servers that can handle the extra processes. 10 viewers on the site with KeepAlive, 80 processes. 100 viewers on the site KeepAlive, 800 processes.

vivhost
11-19-2004, 05:00 AM
Thanks for your reply. I've read your posts in another thread about KeepAlive and I have some reservations about your conclusions ;-) However, if you what you say is TRUE, then I find it rather odd that this is not very commonly documented and disseminated.

But I don't think it's 100% TRUE because here are the current stats with KeepAlive ON and timeout at 5 sec:

Current out BW: 1440 kb/sec
load average: 0.12, 0.05, 0.09
Tasks: 263 total, 3 running, 260 sleeping, 0 stopped, 0 zombie
Cpu(s): 4.3% us, 4.6% sy
no memory swapping (512 MB RAM)

also echoping results are OPTIMAL:
Connected...
TCP Latency: 0.000901 seconds
Sent (85 bytes)...
Application Latency: 0.035958 seconds
282 bytes read from server.
Elapsed time: 0.046071 seconds

So you can see, KeepAlive can be on and not cause resource degradation or response latency. The question remains as to why the KeepAliveTimeout value should make such a big difference in performance, but empirically I can determine its optimal value.

Jakiao
11-19-2004, 08:10 AM
263 total tasks isn't a lot for what I was saying. For me, KeepAlive generated over 600 processes due to the extreme usage. Current out bandwidth for you is 1.406 Mbps. In my case, it's about 12 Mbps.

At some point, KeepAlive only damages the system resources. 263 processes RAM/CPU usage is far less than 600 processes usage of RAM/CPU.

vivhost
11-19-2004, 12:20 PM
I thought that a 10 mbit line only goes up to 1.4 Mbps or so.
10 mbit = ~1.4 MB
Are you on a bigger line or am I mistaken in my calculations?

Chrysalis
11-19-2004, 12:43 PM
the default setting of 300 seems whacky.

Jakiao
11-19-2004, 01:58 PM
10 mbit = 10 Mbps
10 mbit = 1.25 MBps

All of my servers are on a 100 Mbps connection using gigabit ethernet cards connected to a private switch with a private 1000 Mbps LAN.

The ratio for megabit to megabyte is the following

1 Megabyte * (8 Megabits per 1 Megabyte)

The ratio for Megabyte to Megabit is the following

1 Megabit * (1 Megabyte per 8 Megabits)

vivhost
11-19-2004, 02:36 PM
OK, then it makes sense. I would image it somewhat difficult to handle 100 Mbps peak traffic on one box only, unless it has major CPU power, memory and disk speed available.

Jakiao
11-19-2004, 02:40 PM
We don't hit a peak at 100 Mbps. Our peak is around 12 Mbps per day internet bandwidth. The last time we went above 20 Mbps for a sustained period was before we had the LAN in place.

hiryuu
11-19-2004, 06:11 PM
Consider using thttpd or squid for the images. The one process per request model is very expensive for just basic byte shovelling.