Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

According to Methods and Best Practices for High Performance eCommerce with the Magento Enterprise Edition (registration required) keep alive should be off (for high traffic sites)

mod_qos can also disable keep-alive support when the server if running out of free connections.

So the question is, should I have keep-alive disabled/enabled in a low (360Mb) memory server, is there a benefit on keeping keep-alive on?

Side question: has keep-alive anything to do with having a lot of TIME_WAIT connections according to nestat?

Are TIME_WAIT connections wasting server resources, should i try (how?) to keep their number low?

share|improve this question
1  
Near duplicate: serverfault.com/questions/73812/… –  Jesper Mortensen Nov 20 '09 at 7:45

2 Answers 2

up vote 3 down vote accepted

The benefit from having keep-alive on is that a client will be able to request more than one entity from your server without having to create another TCP connection (3-way handshake with its round-trips included). The problem with this is that if, say, you have a connection limit in apache set to 300, if there's 300 active connections all the others will have to wait until the first 300 clients are done and/or the timeout expires.

Disabling keep-alive will force the clients to create 1 connection per request. When the socket is properly closed on both ends, it goes into the TIME_WAIT status, as you've noticed. This happens to ensure that the port used in that connection does not receive data from a previous connection for a while before being available (see this, but there's much more out there). In my linux system, /proc/sys/net/ipv4/tcp_fin_timeout is set to 60 seconds. You can try reducing that, but don't go too far down. How far? It depends on how many connections per second you are getting. For 100-200req/s, don't bother changing the default.

share|improve this answer

On a low-memory server, you're going to run into issues with keepalives turned on at any sort of scale. This is because apache creates one thread or process per connection, allocating by default 8 MB of stack on Linux (which can be adjusted down via Apache config, to what degree is application-dependent). On your 360 MB server, that is likely to be an issue if every client is holding open at least one and possibly two connections.

This is, in fact, a major reason that event-based web servers like nginx and lighttpd were created - to allow systems to handle tens of thousands of connections using sane amounts of memory.

So, I'd turn off keppalives in your situation and live with the performance impact on clients. Or perhaps use something like nginx in front of apache to handle user-facing connections, proxying requests to Apache. This is a very common model, effectively treating Apache as "thread pool" for potentially blocking operations like disk or database access.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.