0

I have an 8 core server which will be running Varnish in front of a HTTP server, both on the same machine.

How can I restrict Varnish to use no more than 4 cores?

I have read of the worker pools in the documentation but it also says this:

"Although Varnish threading model allows you to use multiple thread pools, we recommend you to do not modify this parameter. Based on our experience and tests, we have seen that 2 thread pools are enough. In other words, the performance of Varnish does not increase when adding more than 2 pools.

Note If you run across the tuning advice that suggests to have a thread pool per CPU core, rest assured that this is old advice. We recommend to have at most 2 thread pools, but you may increase the number of threads per pool."

So it seems 2 thread pools is sufficient. Does that mean only two CPU cores are used in that case?

Searching through the documentation I so far haven't found a clear answer.

user1796995
  • 313
  • 4
  • 17

1 Answers1

0

To the best of my knowledge, Varnish doesn't have a built-in way to limit the number of cores it runs on. You'll need to manipulate how the process runs at the operating system level. Assuming you're on Linux, the easiest way to do so would be to modify the startup command to use taskset to pin the process to the specified cores or range of cores. For example, in a service unit override:

# /etc/systemd/system/varnish.service.d/override.conf
ExecStart=
ExecStart=/usr/bin/taskset -c 4-7 /usr/sbin/varnishd \
  -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

This will restrict the varnishd process to the fifth, sixth, seventh, and eight cores. If you have hyperthreading enabled, it gets a bit trickier; your eight physical cores will present as 16 logical cores, with the "real" cores interwoven with the "virtual." In that case you might try taskset -c 8,10,12,14 or taskset -c 9,11,13,15, or if you don't care about restricting Varnish to physical cores, taskset -c 8-15.

Your other options include setting up cgroups or containerizing Varnish (or virtualizing the system, but I'm assuming that's not on the table). If the taskset option won't work for you, or if you're not running on Linux, please update your question with additional information.

mwp
  • 8,217
  • 20
  • 26