I'm setting up a VPS with 4 vCPU that will be running a single website.
Most places recommend to set the nginx worker_processes
config to the number of cpus, so in this case 4.
The server will also be running a few other services (mysql, memcached mainly) that will be used by the website.
In that current scenario, is it still recommended to have worker_processes
set to 4 or would there be benefits to limiting it to 3 for instance?
Edit: Also running php, via php-fpm - don't know how I didn't think that was relevant
In this case, even 1 should be fine, as MySQL and Memcache will likely use much more CPU than nginx. As I imagine, you will also run some kind of scripting language on it as well, which would be even more intensive.
It for sure depends on the load you are expecting on your VPS.
Normally I would just go with the recommendation and let the underlying OS do its job to get the most out of your VPS, though Nginx is quite ressource lightweight and might do fine as well on one core only.
In this instance there is no harm in setting the worker processes to the same as your CPU cores.
Most of the processor operations that NGINX performs are basic enough that they will be handled in L1 cache of your CPU, and will not impact other services on your server.
As always, it depends on the server load and your configuration, however, I run a website that receives around 6,000,000+ hits per day and the CPU does not even reach 10%. It's also running MySQL and PHP-FPM, and APM for caching.