Should I enable KeepAlive on Apache backend with Varnish as frontend

apache-2.2varnish

I'm using Varnish as a frontend with Apache 2 as backend on my web server. What are the pros and cons of Apache's KeepAlive in this setting?

Apache and Varnish run on the same server now, but I could put them on different servers in the future.

Best Answer

Pro:

  • TCP handshake between Varnish and Apache not needed for every single request, reducing overhead.

Con:

  • If your Varnish service wanted to DoS your Apache service with connection exhaustion, it's easier for it to do so..?

Can you clarify what's prompting this question? HTTP connection keep-alive is implied in HTTP 1.1 and on by default in every major web server for a good reason; it's a performance improvement (though it will be a very small one with no latency between services), with a couple of denial-of-service-related caveats that aren't applicable when Apache's only client is Varnish.

I'd even recommend increasing Apache's KeepAliveTimeout higher than the default of 5 seconds, to let Varnish continue to re-use the same pool of connections.