Resolved [alert] 32414#0: socket() failed (24: Too many open files) while connecting to upstream

Pinocchio

New Pleskian
Hi,

Today, my website reached 4.000 concurrent users and i got lots of errors like:

[alert] 32414#0: .... socket() failed (24: Too many open files) while connecting to upstream.

How do I fix this?
 
Increase maximum number of open files:

# ulimit -n 8192

To increase these limits permanently:

  1. Add the following lines in /etc/security/limits.conf file before # End of file line:
    # tail -n4 /etc/security/limits.conf
    * soft nofile 8192
    * hard nofile 8192

    # End of file

  2. Reboot the server to apply these changes.
 
Thanks, I added those lines and saved the file. Shall I reboot using the following command?

# service sw-engine restart && service sw-cp-server restart
 
The issue can come from different sources on your server. For Debian, for example, consider increasing the following values to avoid hitting open file limits (web server / mail / PHP):

/etc/security/limits.conf

Code:
*         hard    nofile      1048576
*         soft    nofile      1048576
root      hard    nofile      1048576
root      soft    nofile      1048576

/etc/sysctl.d/10-own-settings.conf

Code:
# Kernel 5.11 will raise those limits automatically based on host memory, but 5.10 is still using default low values: 8192 / 128
fs.inotify.max_user_watches = 560144
fs.inotify.max_user_instances = 1024

/etc/systemd/system.conf

Code:
DefaultLimitNOFILE=1048576:1048576
DefaultLimitNPROC=1048576:1048576

/etc/systemd/user.conf

Code:
DefaultLimitNOFILE=1048576:1048576
DefaultLimitNPROC=1048576:1048576

/opt/plesk/php/*/etc/php-fpm.conf

Code:
rlimit_files = 524288

/etc/nginx/nginx.conf

Code:
# CPU core count * 1024
worker_connections 32768;

/etc/nginx/ulimit.global_params

Code:
worker_rlimit_nofile 524288;

/etc/dovecot/conf.d/10-master.conf

Code:
default_client_limit = 4299

/etc/systemd/system/nginx.service.d/override.conf

Code:
[Service]
LimitNOFILE=1048576

/etc/systemd/system/sw-cp-server.service.d/override.conf

Code:
[Service]
LimitNOFILE=524288

/etc/systemd/system/mariadb.service.d/override.conf

Code:
[Service]
LimitNOFILE=524288

/etc/apache2/envvars

Code:
APACHE_ULIMIT_MAX_FILES='ulimit -n 524288'

For other OSes, look for the corresponding settings. It also makes sense to monitor the configuration for changes, for example via Ansible, to make it more resilient.
 
The issue can come from different sources on your server. For Debian, for example, consider increasing the following values to avoid hitting open file limits (web server / mail / PHP):

/etc/security/limits.conf

Code:
*         hard    nofile      1048576
*         soft    nofile      1048576
root      hard    nofile      1048576
root      soft    nofile      1048576

/etc/sysctl.d/10-own-settings.conf

Code:
# Kernel 5.11 will raise those limits automatically based on host memory, but 5.10 is still using default low values: 8192 / 128
fs.inotify.max_user_watches = 560144
fs.inotify.max_user_instances = 1024

/etc/systemd/system.conf

Code:
DefaultLimitNOFILE=1048576:1048576
DefaultLimitNPROC=1048576:1048576

/etc/systemd/user.conf

Code:
DefaultLimitNOFILE=1048576:1048576
DefaultLimitNPROC=1048576:1048576

/opt/plesk/php/*/etc/php-fpm.conf

Code:
rlimit_files = 524288

/etc/nginx/nginx.conf

Code:
# CPU core count * 1024
worker_connections 32768;

/etc/nginx/ulimit.global_params

Code:
worker_rlimit_nofile 524288;

/etc/dovecot/conf.d/10-master.conf

Code:
default_client_limit = 4299

/etc/systemd/system/nginx.service.d/override.conf

Code:
[Service]
LimitNOFILE=1048576

/etc/systemd/system/sw-cp-server.service.d/override.conf

Code:
[Service]
LimitNOFILE=524288

/etc/systemd/system/mariadb.service.d/override.conf

Code:
[Service]
LimitNOFILE=524288

/etc/apache2/envvars

Code:
APACHE_ULIMIT_MAX_FILES='ulimit -n 524288'

For other OSes, look for the corresponding settings. It also makes sense to monitor the configuration for changes, for example via Ansible, to make it more resilient.
I'll check those. Thank you so much!
 
Back
Top