Most UNIX-like operating systems, including Linux and macOS, provide ways to limit and control the usage of system resources such as threads, files, and network connections on a per-process and per-user basis. These "ulimits" prevent single users from using too many system resources. Sometimes, these limits have low default values that can cause a number of issues in the course of normal MongoDB operation.
mongos each use threads and file
descriptors to track connections and manage internal operations. This
section outlines the general resource utilization patterns for MongoDB.
Use these figures in combination with the actual information about your
deployment and its use to determine ideal
- track each incoming connection with a file descriptor and a thread.
- track each internal thread or pthread as a system process.
- 1 file descriptor for each data file in use by the
- 1 file descriptor for each journal file used by the
- In replica sets, each
mongodmaintains a connection to all other members of the set.
In addition to the threads and file descriptors for client connections,
mongos must maintain connections to all config servers and
all shards, which includes all members of all replica sets.
mongos, consider the following behaviors:
mongosinstances maintain a connection pool to each shard so that the
mongoscan reuse connections and quickly fulfill requests without needing to create new connections.
- You can limit the number of incoming connections using
net.maxIncomingConnectionsrun-time option. By restricting the number of incoming connections you can prevent a cascade effect where the
mongoscreates too many connections on the
Review and Set Resource Limits¶
You can use the
ulimit command at the system prompt to check
system limits, as in the following example:
$ ulimit -a -t: cpu time (seconds) unlimited -f: file size (blocks) unlimited -d: data seg size (kbytes) unlimited -s: stack size (kbytes) 8192 -c: core file size (blocks) 0 -m: resident set size (kbytes) unlimited -u: processes 192276 -n: file descriptors 21000 -l: locked-in-memory size (kb) unlimited -v: address space (kb) unlimited -x: file locks unlimited -i: pending signals 192276 -q: bytes in POSIX msg queues 819200 -e: max nice 30 -r: max rt priority 65 -N 15: unlimited
ulimit refers to the per-user limitations for various
resources. Therefore, if your
mongod instance executes as a
user that is also running multiple processes, or multiple
mongod processes, you might see contention for these
resources. Also, be aware that the
processes value (i.e.
refers to the combined number of distinct processes and sub-process
On Linux, you can change
ulimit settings by issuing a command in the
ulimit -n <value>
There are both "hard" and the "soft"