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
Mostly spiking backend connections has little to do with your varnish configuration but alot to do with the cachability of your site.
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?cat syslog | grep "varnish"