Keepalive Sessions

Traian Bratucu traian.bratucu at
Mon Dec 20 11:59:34 CET 2010

I must point out another "exception" you may want to be aware of. 

When using keep-alive between varnish and the backend, if the client sends a request which times out (backend does not respond in the specified timeout time) then varnish will retry the request (hardcoded logic) one more time. Even if you don't specify any restarts in the VCL.

This is no problem normally, unless your request was a POST which the backend takes a long time to process. With several backends such a POST request which times out on the first try will be retried, and you will have yourself a double-post. In my case the backends were timing out on processing some long email lists and I was finding that all emails were sent twice. And that sucks :)

On Mon, Dec 20, 2010 at 08:04:33AM +0100, Frank Helmschrott wrote:
> i wonder how the thing is with keep alive sessions from apache when
> using it behind a varnish cache server. Doesn't keep alive make sense
> here as all the connection come from the varnish cache (one source)
> instead of the users (many sources). I don't know how these sessions
> work in detail but thats what came to my tired mind on early monday
> morning :)

Varnish uses (and likes) keep-alive to the back-end. You want your backend
to support keep-alive, since there's little point in re-establishing
connections all the time. There's a "backend connections reused" counter
that'll tell indicate how efficient Varnish is at taking advantage of
keep-alive (and recycled, which is much the same thing).

There's one exception, though: When you are using pipe (not pass), you want
to set "connection: close" in vcl_pipe to disable keep-alive. This is
because Varnish only sees the first request in a piped session - if the
first request is piped, the next requests will be too. This is a problem
if you need different backends for the requests; have cached the
subsequent requests; or if you need the x-forwarded-for header or other
varnish-manipulated headers on the subsequent requests.

But other than pipe, you really want to use keep-alive.

- Kristian

More information about the varnish-misc mailing list