php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream
If I could downvote the answer from @Artsiom forever, I would.
pm.max_children = 4000
means up to 4K worker processes. If traffic flows in very fast and together with pm.max_requests = 0
, the workers are never recycled, the RAM usage will grow indefinitely over time and the server will be in out of memory condition (down, frozen) sooner or later.
PHP-FPM max_children should be raised carefully and gradually while monitoring swap usage.
You can use a formula liks the following:
pm.max_children = ((total RAM in MB) - (how much MySQL and others take in RAM)) / 80
Where 80 MB is average weight of a PHP-FPM workers process if your PHP framework is light. For heavy things like Magento 2, take at least 128 MB instead.
And the pm.max_requests
should be some "limited" value.
In higher spec servers you can indeed raise it (10000, for example), while on low end servers this should be set to smallest (e.g. 500, to even 100) to reduce RAM "usage" fluctuations. But it no scenario I would set it to 0 (unlimited) because a value of 0 implies that your code / PHP and all of its extensions are absolutely free from memory leaks. Only then it would be fine to be set to 0!!!
This happens because the operating system rejects nginx's attempts to connect to a unix socket.
The reason is either the maximum number of socket connections or the maximum number of unhandled socket connections has been exceeded.
Checking the limits:
sysctl net.core
We are interested in the lines:
net.core.somaxconn = 128
net.core.netdev_max_backlog = 200
Because of them, an error occurs, since the maximum number of connections is 128 and the maximum number of unprocessed is 200
Change the limits, write the lines in the / etc / sysctl.conf file
nano /etc/sysctl.conf
add
net.core.somaxconn = 20000
net.core.netdev_max_backlog = 65535
Apply parameters
sysctl -p
Restart php-fpm
service php-fpm restart
Source: https://galaxydata.ru/community/sock-failed-11-resource-temporarily-unavailable-459