Number of Files Opened: Difference between revisions
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux" |
No edit summary |
||
| Line 24: | Line 24: | ||
You can see the limits set by running {{code|ulimit}} on the bash shell. | You can see the limits set by running {{code|ulimit}} on the bash shell. | ||
{{highlight|lang=terminal|code= | {{highlight | ||
# ulimit -n | | lang = terminal | ||
| code = # ulimit -n | |||
1024 | |||
}} | }} | ||
This tells you that the maximum number of files you can have in this session is 1024 files. | |||
{{ | |||
# | For normal shell login sessions, you can specify these limits in {{code|/etc/security/limits.conf}}. To change a user's soft and hard file limits, add the following lines: | ||
{{Highlight | |||
| code = ## In /etc/security/limits.conf | |||
username soft nofile 16384 | |||
username hard nofile 32768 | |||
| lang = text | |||
}} | }} | ||
== Systemd service == | |||
Services that are started by systemd will not adhere to the limits specified in the <code>/etc/security/limits.conf</code> file (because those are set by PAM?). You will have to change the service file and specify the limits there instead. | |||
For example: | |||
{{Highlight | |||
| code = [Unit] | |||
Description=Galaxy Web Service | |||
After=network.target | |||
[Service] | |||
Type=simple | |||
User=galaxy | |||
ExecStart=/galaxy/run.sh | |||
# ExecStop=/galaxy/run.sh stop | |||
# ExecReload=/galaxy/run.sh restart | |||
Restart=always | |||
LimitNOFILE=65536 | |||
[Install] | |||
WantedBy=multi-user.target | |||
| lang = text | |||
}} | |||
== See Also == | == See Also == | ||
* http://blog.thecodingmachine.com/content/solving-too-many-open-files-exception-red5-or-any-other-application | * http://blog.thecodingmachine.com/content/solving-too-many-open-files-exception-red5-or-any-other-application | ||
{{Navbox Linux}}[[Category:Linux]] | {{Navbox Linux}}[[Category:Linux]] | ||
Revision as of 16:54, 4 October 2022
Linux allows you to control how many opened file descriptor an user can have at any one time.
System-Wide Settings
To show the number of files opened on a system, run:
# cat /proc/sys/fs/file-nr
1536 0 793120
The fields are:
- Current number of opened files
- Number of free allocated file descriptors
- Maximum number of file descriptors for the whole system
You may change this value by:
# cat <new value> > /proc/sys/fs/file-nr
## Edit <code>/etc/sysctl.conf</code> so that there is a line
## fs.file-max = <new value>
Per-User Settings
You can see the limits set by running ulimit on the bash shell.
# ulimit -n
1024
This tells you that the maximum number of files you can have in this session is 1024 files.
For normal shell login sessions, you can specify these limits in /etc/security/limits.conf. To change a user's soft and hard file limits, add the following lines:
## In /etc/security/limits.conf
username soft nofile 16384
username hard nofile 32768
Systemd service
Services that are started by systemd will not adhere to the limits specified in the /etc/security/limits.conf file (because those are set by PAM?). You will have to change the service file and specify the limits there instead.
For example:
[Unit]
Description=Galaxy Web Service
After=network.target
[Service]
Type=simple
User=galaxy
ExecStart=/galaxy/run.sh
# ExecStop=/galaxy/run.sh stop
# ExecReload=/galaxy/run.sh restart
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target