Question

We're operating an API that at times comes under very heavy traffic at certain periods. Under normal circumstances using varnishstat we can see 0 backend connections are required. We interpret this as Varnish being able to serve all data from the cache successfully.

When traffic spikes we see a surge in backend connections, which in turn open DB connections causing DB resources to spike. It seems Varnish gets bypassed in high traffic.

We've tweaked max_connections settings in MySQL and tuned both varnish config files. We're running with 4 thread pools with a min 200 threads and max 4000. We've allocated a large amount of memory to varnish (8GB out of 15GB).

The question is why do backend connections spike so much with traffic? This is surely what Varnish is supposed to prevent. I'm assuming that we've got something wrong in the configuration but cannot find help on what we can update to prevent so many requests bypassing varnish in high traffic.

Any help is appreciated

Was it helpful?

Solution

Mostly spiking backend connections has little to do with your varnish configuration but alot to do with the cachability of your site.

  • Are there cookies that prevents you from caching efficiently? You can chose to strip them or remove all but chosen ones, there are examples for both on the varnish site.
  • Do a varnishstat and check your hit rates during peaks. Is it a good cache hitratio? Is it the same as during low load? If it's the same or higher in low load it's easy to work on improving it at any time.
  • Do a varnishtop -i txurl to see what requests are the most frequently sent to backend servers. Maybe it's some URLs that are just not cached due to faulty headers? Maybe some pages can be cached longer? Maybe some parts of the pages can be cached with ESI?
  • Make sure your varnish is not crashing during peaks (leaving it with empty cache). You can see crash info by a cat syslog | grep "varnish"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top