Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared Varnish cache across multiple servers

Tags:

varnish

We have 4 Varnish servers behind a load balancer. By default, each Varnish server has its own cache. They do not share a cache. This is a problem because it takes 5-6 page loads of a particular page to get it cached in every server.

To circumvent this problem, I changed the Varnish storage from memory to file. The file is stored on a disk drive which is shared across all the Varnish servers. All Varnish servers are able to start correctly but somehow they are still using their own cache. I did confirm that the cache file is being written into by Varnish.

Any idea how to solve this problem?

like image 862
Neerav Mehta Avatar asked Oct 21 '14 19:10

Neerav Mehta


People also ask

Where does Varnish store its cache?

Varnish Cache stores content in pluggable modules called storage backends. It does this via its internal stevedore interface.

How does Varnish caching work?

Varnish cache is a web application accelerator also known as caching HTTP reverse proxy. It acts more like a middle man between your client (i.e. user) and your web server. That means, instead of your web server to directly listen to requests of specific contents all the time, Varnish will assume the responsibility.

What is meant by Varnish cache server?

Varnish Cache is a powerful, open source HTTP engine/reverse HTTP proxy that can speed up a website by up to 1000 percent by doing exactly what its name implies: caching (or storing) a copy of a webpage the first time a user visits.

Is Varnish Cache good?

You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.


1 Answers

I know the question is old, but for future reference:

The file backend stores objects in memory backed by an unlinked file on disk with mmap.

(from https://www.varnish-cache.org/docs/4.0/users-guide/storage-backends.html)

The important word here is unlinked, which means that the file is not available any more outside of the process once it has happened. It can still be used by the creating process which holds a handle on it vie mmap. From the unlink(2) man page:

If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed.

So in a nutshell: no, the same file backend cannot be shared, and besides that, there is currently no known way to share the cache itself between several varnish instances (most existing techniques involve chaining instances to replicate the cache content, but this is replicating, not sharing).

like image 113
cdelacroix Avatar answered Sep 18 '22 15:09

cdelacroix