If you are seeing Mongo soft rlimits warnings in your logs, or a WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
when you login to mongo shell via mongo
from the commandline, or any mysterious/unexplained mongo connection errors... follow this how-to exactly and it will resolve the issue for you.
(Source of this how to found at basho/basho_docs#1402)
First file:
sudo vi /Library/LaunchDaemons/limit.maxfiles.plist
...containing:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>65536</string>
<string>65536</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
Second file:
sudo vi /Library/LaunchDaemons/limit.maxproc.plist
...containing:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
Please confirm that both these files are owned by root:wheel and have permissions -rw-r--r--
. This should be the default but it's wise to check. The chmod command to do that is sudo chmod 644 <filename>
.
Doing the above will cause system limits to set themselves correctly upon restart. This can be confirmed by typing launchctl limit
into a terminal.
Once system limits are properly set, it remains necessary to set session limits. This is best done by editing bashrc:
sudo vi /etc/bashrc
You need to add the following lines to the end of the file:
ulimit -n 65536
ulimit -u 2048
As with the other files above, make sure the bashrc file has -rw-r--r--
permissions.
After all this is done, restart the computer and type ulimit -n into a terminal. You should see confirmed that the maxfiles is 65536. You will no longer see soft rlimits warnings when you login into mongo shell with mongo
from the command line!
The above method is suitable for computers that are happy to keep a high open files limit in the long run. However, if you wish to change the limit only for the current session, you may skip modifications to files and simply enter the following into the terminal:
sudo launchctl limit maxfiles 65536 65536
sudo launchctl limit maxproc 2048 2048
ulimit -n 65536
ulimit -u 2048
These settings will expire; the ulimit settings upon relaunch of the terminal and the launchctl settings upon restart of the computer.
This was very useful; thank you!