How much value should I set to resolve the Too many open files error on Nginx?

I run wordpress websites on Nginx server (v 1.21.6).

And recently i saw error like below.

2022/03/07 19:43:41 [crit] 563445#563445: accept4() failed (24: Too many open files)
2022/03/07 19:43:42 [crit] 563445#563445: accept4() failed (24: Too many open files)

I restart Nginx, website access works fine.

And then, I googled to solve this problem, a lot of tutorials and values came up that confused me.

My system info

ulimit -Hn
1048576
ulimit -Sn
1024

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7581
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7581
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Then i added the following values to /etc/sysctl.conf.

fs.file-max = 70000

Did this solve all my problems?

If that’s not the case, I’d love to hear some advice on whether I should add another setting.

Thank you.

Answer

I added the following values to /etc/sysctl.conf.

fs.file-max = 70000

The sysctl command is used to modify kernel parameters at runtime. It can take a single parameter as an argument i.e. sysctl fs.file-max to read the current value of a parameter or for example sysctl fs.file-max=98036 to set that value , or with sysctl -p /path/to/file read parameters from a file.

The file /etc/sysctl.conf (and some others) is the default preload/configuration file for kernel parameters.

Simply changing that file does not effect any change.

You will need to either reboot or run [sudo] sysctl --system to apply the changed settings there.


The ulimit command gets/sets the resource limits that the kernel enforces, for a particular user or process.


Although you can set resource limits with ulimit that are “unlimited” or seemingly more realistic, but that still have a value that exceeds the associated kernel parameter, doing so won’t make that happen.

The system has finite resources and when there is such a kernel parameter, that will be the upper limit available.

Attribution
Source : Link , Question Author : cheonmu , Answer Author : Bob

Leave a Comment