[−][src]Module async_listen::errors
Documentation of the Error Hints
This page is the destination of the links shown by
error_hint
.
List of errors having a hint:
Too Many Open Files
Posix Name | EMFILE |
---|---|
Message | Too many open files (os error 24) |
Hint | Increase per-process open file limit |
Link | https://bit.ly/async-err#EMFILE |
Common Causes
- File descriptor limit for the process is too low
- Limit of number of simultaneous connections is either too high or unimplemented
The (2) can be fixed by applying backpressure
abstraction from this
crate.
The rest of this section discusses how to change file decriptor limit.
Choosing a Limit
There is no one good strategy. But here are few hints:
- It must be lower than limit on simultaneous connections.
- Sometimes it's several times lower, like if you need to open a file or to open a backend connection for each client, it should be 2x lower plus some offset.
- Measure an average memory used by each client and divide memory available by that value.
We use 10000
as an example value later in the text.
Linux
Either use ulimit -n
in the same shell:
$ ulimit -n 10000
$ ./your_app
If you get the error, you need superuser privileges:
$ ulimit -n 10000
ulimit: value exceeds hard limit
$ sudo -s
# ulimit -n 10000
# su your_user
$ ./your_app
On most systems there is /etc/security/limits.conf
to make persistent
changes:
your_user hard nofile 10000
your_user sort nofile 10000
Run su your_user
to apply changes to your current shell without reboot.
Docker
Docker uses limit of 65535
by default. To increase it add a parameter:
docker run --ulimit nofile=10000:10000 ...
MacOS
On MacOS raising ulimit doesn't require permissions:
$ ulimit -n 10000
$ ./your_app
Too Many Open Files in System
Posix Name | ENFILE |
---|---|
Message | Too many open files in system (os error 23) |
Hint | Increase system open file limit |
Link | https://bit.ly/async-err#ENFILE |
Common Causes
- Per-process file descriptor limit is larger than system one
- File descriptor limit on the system is too small
- Limit of number of simultaneous connections is either too high or unimplemented
The (3) can be fixed by applying backpressure
abstraction from this
crate.
Changing (1) is described in the section above.
The rest of this section discusses how to change system file decriptor limit.
Choosing a Limit
Usually system limit depends on the memory and doesn't have to be increased. So be careful and consult your system docs for more info.
Linux
Checking the limit:
$ cat /proc/sys/fs/file-max
818354
Setting a limit:
$ sudo sysctl fs.file-max=1500000
This only works until reboot. On some systems, to preserve this setting after reboot you can run:
$ sudo sysctl -w fs.file-max=1500000
(Note -w
)
MacOS
Checking a limit:
launchctl limit maxfiles
Setting a limit, until reboot:
sudo sysctl -w kern.maxfiles=20480
To make the permanent change, add the following to /etc/sysctl.conf
:
kern.maxfiles=65536
kern.maxfilesperproc=65536