# mongodb ** WARNING: soft rlimits too low. rlimits set to 89999 processes



## andrian (Feb 24, 2020)

Hi, please help me. How to change "soft rlimits" ?


----------



## SirDice (Feb 24, 2020)

Read the top of the /usr/local/etc/rc.d/mongod script.


----------



## andrian (Feb 25, 2020)

Thanks for the help. I looked but didn't understand what I should do?
I see the ribbon that I probably need!

```
if checkyesno mongod_limits; then
                eval `/usr/bin/limits -e -U ${mongod_user}` 2>/dev/null
```


----------



## andrian (Feb 25, 2020)

i tried
`# vi /etc/rc.conf`
and аdded a line

```
mongod_enable="YES"
mongod_limits="NO"
```
but again after the restart the same message

```
2020-02-25T16:46:12.884+0200 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 89999 processes, 3770469 files. Number of processes should be at least 1.88523e+06 : 0.5 times number of files.
```


----------



## SirDice (Feb 25, 2020)

Add `mongod_limits="YES"` to rc.conf (it defaults to NO).


----------



## andrian (Feb 25, 2020)

I changed

```
mongod_enable="YES"
mongod_limits="YES"
```
 and restarted, but when I went into the mongo console - I see the message again.

```
root@mongologsX:/home/andrian # mongo
MongoDB shell version: 3.2.11
connecting to: test
Server has startup warnings: 
2020-02-25T16:59:12.456+0200 I CONTROL  [initandlisten] 
2020-02-25T16:59:12.456+0200 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 89999 processes, 3770469 files. Number of processes should be at least 1.88523e+06 : 0.5 times number of files.
>
```


----------



## andrian (Feb 25, 2020)

Performed manually:

```
root@mongologsX:/home/andrian # /usr/bin/limits -e -U mongodb
limit cputime unlimited;
limit filesize unlimited;
limit datasize unlimited;
limit stacksize unlimited;
limit coredumpsize unlimited;
limit memoryuse unlimited;
limit memorylocked 64;
limit maxproc unlimited;
limit openfiles unlimited;
limit sbsize unlimited;
limit vmemoryuse unlimited;
limit pseudoterminals unlimited;
limit swapsize unlimited;
limit kqueues unlimited;
limit umtxp unlimited;
root@mongologsX:/home/andrian # mongo
MongoDB shell version: 3.2.11
connecting to: test
Server has startup warnings: 
2020-02-25T16:59:12.456+0200 I CONTROL  [initandlisten] 
2020-02-25T16:59:12.456+0200 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 89999 processes, 3770469 files. Number of processes should be at least 1.88523e+06 : 0.5 times number of files.
>
```


----------



## andrian (Feb 25, 2020)

And


```
root@mongologsX:/home/andrian # /usr/bin/limits -e -U mongodb
limit cputime unlimited;
limit filesize unlimited;
limit datasize unlimited;
limit stacksize unlimited;
limit coredumpsize unlimited;
limit memoryuse unlimited;
limit memorylocked 64;
limit maxproc unlimited;
limit openfiles unlimited;
limit sbsize unlimited;
limit vmemoryuse unlimited;
limit pseudoterminals unlimited;
limit swapsize unlimited;
limit kqueues unlimited;
limit umtxp unlimited;
root@mongologsX:/home/andrian # /usr/local/etc/rc.d/mongod restart
Stopping mongod.
Waiting for PIDS: 4042.
Starting mongod.
root@mongologsX:/home/andrian # mongo
MongoDB shell version: 3.2.11
connecting to: test
Server has startup warnings: 
2020-02-25T17:06:03.840+0200 I CONTROL  [initandlisten] 
2020-02-25T17:06:03.840+0200 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 89999 processes, 3770469 files. Number of processes should be at least 1.88523e+06 : 0.5 times number of files.
>
```


----------



## andrian (Feb 25, 2020)

I`ll look at it:

```
root@mongologsX:/home/andrian # limits -a
Resource limits (current):
  cputime              infinity secs
  filesize             infinity kB
  datasize             33554432 kB
  stacksize              524288 kB
  coredumpsize         infinity kB
  memoryuse            infinity kB
  memorylocked         infinity kB
  maxprocesses            89999
  openfiles             3770469
  sbsize               infinity bytes
  vmemoryuse           infinity kB
  pseudo-terminals     infinity
  swapuse              infinity kB
  kqueues              infinity
  umtxp                infinity
```


----------



## SirDice (Feb 25, 2020)

What's the output of `sysctl kern.maxprocperuid`?


----------



## andrian (Feb 25, 2020)

`root@mongologsX:/home/andrian # sysctl kern.maxprocperuid
kern.maxprocperuid: 89999

root@mongologsX:/home/andrian # sysctl kern.maxprocperuid=189999
kern.maxprocperuid: 89999 -> 189999
root@mongologsX:/home/andrian # sysctl kern.maxprocperuid
root@mongologsX:/home/andrian # /usr/local/etc/rc.d/mongod restart
Stopping mongod.
Waiting for PIDS: 4093.
Starting mongod.
root@mongologsX:/home/andrian # mongo
MongoDB shell version: 3.2.11
connecting to: test
Server has startup warnings: 
2020-02-25T17:24:13.800+0200 I CONTROL  [initandlisten] 
2020-02-25T17:24:13.800+0200 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 189999 processes, 3770469 files. Number of processes should be at least 1.88523e+06 : 0.5 times number of files.
>`

Thank you!!!!
Then I'll try myself.


----------



## SirDice (Feb 25, 2020)

Yes, you can set it permanently in /etc/sysctl.conf. If I recall correctly the maxprocperuid is set to a certain value based on the amount of memory, but in some cases you need to adjust it manually. Do keep an eye on kern.maxfiles too. 


```
-n [val]        Select or set the openfiles resource limit.  The system-
                     wide limit on the maximum number of open files per
                     process can be viewed by examining the
                     kern.maxfilesperproc sysctl(8) variable.  The total
                     number of simultaneously open files in the entire system
                     is limited to the value displayed by the kern.maxfiles
                     sysctl(8) variable.
```


----------



## Overhacked (Feb 4, 2021)

SirDice said:


> Add `mongod_limits="YES"` to rc.conf (it defaults to NO).


Replying here to help anyone who gets to this thread via search results, as I did:

In FreeBSD 12.0 and later, you can no longer set mongod_limits="YES". You have to explicitly give the flags to pass to the limits(1) command, because the SERVICENAME_limits="*" variable in /etc/rc.conf is part of the rc.subr(8) script for all services.

Two sensible settings would be:
1. The limits that already apply to the mongodb user: mongod_limits="-U mongodb". You can control these any way you like via login.conf(5).
2. The MongoDB recommended limits: mongod_limits="-n 64000 -u 64000".

Proper settings will prevent MongoDB from complaining at startup: `** WARNING: soft rlimits too low. rlimits set to XXXXXX processes, YYYYYY files. Number of processes should be at least ZZZZZZ : 0.5 times number of files.` Optimal settings, of course, are site-specific.


----------

