Varnish Guru Meditation on timeout

Varnish Guru Meditation on timeout

How to configure the backend connection timeout to avoid Varnish"Error 503 Service Unavailable Backend did not respond. Guru Meditation: XID: 456452130"Update 2009-06-27: You should not have the problem with Varnish 2.0.4 and plone.recipe.varnish 1.0rc11 anymore. Please read the article for details.

Update 2009-06-27: You should not have the problem with Varnish 2.0.4 and plone.recipe.varnish 1.0rc11 anymore.In Varnish 2.0.4 the default value for connect_timeout is 0.4s, first_byte_timeout and between_bytes_timeout options is 60s.The varnish configuration generated by plone.recipe.varnish 1.0rc11 includes nowfirst_byte_timeout = 300s.

For one of my customers, I set up a server with the following chain:

Apache (gzip on) -> varnish -> haproxy -> 3 zeoclients with CacheFu (no compression) -> zeoserver

thanks to Martin Aspeli's uber buildout and Products.PloneOrg for examples.

But Varnish gave me sometimes the error"Error 503 Service Unavailable Backend did not respond. Guru Meditation: XID: 456452130". Not so cool.

I use the default config generated from plone.recipe.varnish.It seems the cause of "Varnish Guru Meditation" errors comes from backend connection timeout, actually the time between the first byte of the response.

The documentation of how to set the timeout was pretty hard to find. Here is what I found:

  • http://varnish.projects.linpro.no/changeset/2642
  • http://varnish.projects.linpro.no/changeset/3406
  • http://iyubo.blogbus.com/logs/35013331.html

In Varnish 2.0.4 the default value for connect_timeout is 0.4s, first_byte_timeout and between_bytes_timeout options is 60s.

In my case, 60s for first_byte_timeout was not enough. So now I start varnish with the following command:

./bin/varnish-instance -p first_byte_timeout=300

Or I can create my own varnish.vcl with:

backend backend_0 {
        .host = "127.0.0.1";
        .port = "5501";
        .first_byte_timeout = 300s;
}

I didn't have any Guru Meditation since I restarted varnish with the option.

And to enable session persistence in haproxy so a user use always the same zeoclient, I put in my templates/haproxy.conf.in:

backend zope
  balance roundrobin
  cookie serverid insert indirect nocache

  server  plone0101 127.0.0.1:${instance1:http-address} cookie p0101 maxconn 2 check inter 2000 rise 2 fall 5
  server  plone0102 127.0.0.1:${instance2:http-address} cookie p0102 maxconn 2 check inter 2000 rise 2 fall 5
  server  plone0103 127.0.0.1:${instance3:http-address} cookie p0103 maxconn 2 check inter 2000 rise 2 fall 5

In Martin Aspeli's buildout, it's only "cookie serverid", and it doesn't work with Varnish 2.0.4, it's not enough. You have to specify how you add the serverid cookie to the request as described in thehaproxy documentation.

I hope it will be useful to someone.

你可能感兴趣的:(Varnish Guru Meditation on timeout)