Varnish hit-for-pass means?

Muneeb Nasir picture Muneeb Nasir · Oct 2, 2012 · Viewed 21.6k times · Source

As Varnish Version 3 has some objects for different operations.

For Example, pass is used when it has to retrieve data from backend. and it uses hit when it finds requesting content in cache.

But I cant understand usage of hit-for-pass. when varnish uses it ? I haven't found any useful material on net which make me clear.

Answer

lkarsten picture lkarsten · Oct 3, 2012

A hit_for_pass object is made to optimize the fetch procedure against a backend server.

For ordinary cache misses, Varnish will queue all clients requesting the same cache object and send a single request to the backend. This is usually quickest, letting the backend work on a single request instead of swamping it with n requests at the same time.

Remember that some backends use a lot of time preparing an object; 10 seconds is not uncommon. If this is the front page HTML and you have 3000 req/s against it, sending just one backend request makes a lot of sense.

The issue arises when after Varnish has fetched the object it sees that it can't be cached. Reasons for this can be that the backend sends "Cache-Control: max-age=0", or (more often) a Set-Cookie header. In this case you have somewhere between 3,000 and 30,000 clients (3k req/s * 10sec) sitting idle in queue, and for each of these clients the same slow one-at-a-time backend request must complete to serve them. This will ruin your site response time.

So Varnish saves the decision that this request cannot be cached by creating a hit_for_pass object.

On the next request for the same URL, the cache lookup will return a hit_for_pass object. This signals that multiple fetches may be done at the same time. Your backend might not be too happy about it, but at least Varnish isn't queuing the clients for no reason.