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?
Varnish Cache stores content in pluggable modules called storage backends. It does this via its internal stevedore interface.
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With