I was wondering if anyone has any comments / benchmarks / suggestions on Varnish Vs Memcache when used to serve content (usually 2-5kb JS file depending on the parameters in request; thousands of diff files are possible)

Currently we are using nginx + Varnish + LAMP to do this.

I was reading about memcached module of nginx and was wondering if anyone has any benchmarks for caching content in Memcache and serving them directly from nginx (or pulling from LAMP incase of a miss), rather then passing the request to Varnish and letting it do the same job.

Overall, is there any benchmark on setting and getting (as well as occassional purging) of content (usually 2-5kb) with Memcache Vs Varnish



IMHO this is not a question of "memcache vs varnish", but "varnish with or without memcache", and I think you should by all means use memcache whenever you can. In fact, memcache/memcached cahes data and objects from a database, whilst Varnish is an HTTP accelerator for "content-heavy dynamic websites".

Both work together really well, and for example a LEMP (or LNMP) platform with PHP-FPM, Varnish and memcached to host blogs and CMS (I use that config for my WordPress sites) is absolutely fantastic. In the case of WordPress, the help of plugins like W3 Total Cache that manage Varnish and memcached for different aspects of the caching makes everything transparent, and the performance is gorgeous.

So don't worry about installing it: just do it and enjoy the benefits ;)

  • We already use memcache massively and have 5 dedicated servers for memcaching with abour 20GB cache available. Memcache is giving us a good layer of cache before we reach the databases. My Concern is that since our response size is also small (less than 5 kbs always, average being 1kb), I can save the whole in memcache and then can eliminate the need of Varnish. – Sparsh Gupta Mar 2 '12 at 12:46
  • Oh, I see. You want to kill one of the "intermediate layers", right? I think both are useful for different things, and I'm not sure getting rid of Varnish would improve your performance. Your document size is pretty low, yes, but even then caching will always help, won't it? – javipas Mar 2 '12 at 13:01
  • Right, but then the difference would be that if its in Memcache I can use the nginx memcache module to directly fetch the value for my keys and elimiate the need of reverse proxing it to Varnish HTTP server. Right now any request comes to nginx server -> varnish server and then sent back. So its resolved at both ends, whereas by only using memcache, I will save this extra resolution time at Varnish but then my comparison need to consider fetching setting times of memcache and varnish – Sparsh Gupta Mar 2 '12 at 13:04
  • Understood. I guess your best bet is to test and try both configurations to see wich one really performs better. Good luck with it! – javipas Mar 2 '12 at 14:59
  • The fastest IMHO is when you place Varnish' cache file on a ramdisk. – Daniel W. Jun 23 '15 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.