Skip to content

Instantly share code, notes, and snippets.

@ajaxsys
Forked from tamitutor/osx-mongodb-rlimits-fix.md
Created November 23, 2015 13:06
Show Gist options
  • Select an option

  • Save ajaxsys/e2c894bd3b95b1225eb4 to your computer and use it in GitHub Desktop.

Select an option

Save ajaxsys/e2c894bd3b95b1225eb4 to your computer and use it in GitHub Desktop.

Revisions

  1. @tamitutor tamitutor revised this gist Mar 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion osx-mongodb-rlimits-fix.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    If you are seeing **soft rlimits warnings** 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, follow this how-to exactly and it will resolve the issue for you.
    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 https://github.com/basho/basho_docs/issues/1402)

  2. @tamitutor tamitutor renamed this gist Mar 19, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @tamitutor tamitutor renamed this gist Mar 19, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @tamitutor tamitutor renamed this gist Mar 19, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @tamitutor tamitutor created this gist Mar 19, 2015.
    88 changes: 88 additions & 0 deletions OSX-Mongodb-rlimits-Fix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    If you are seeing **soft rlimits warnings** 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, follow this how-to exactly and it will resolve the issue for you.

    (Source of this how to found at https://github.com/basho/basho_docs/issues/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.