22Linux ``ulimit`` Settings
33=========================
44
5+ .. default-domain:: mongodb
6+
57The Linux kernel provides a system to limit and control the number of
68threads, connections, and open files on a per-process and per-user
7- basis. These limits prevent renegade processes from using too many
8- system resources. Sometimes, these limits, as configured by the
9- distribution developers, are too low for MongoDB and can cause a
10- number of issues in the course of normal MongoDB operation.
9+ basis. These limits prevent single users from using too many system
10+ resources. Sometimes, these limits, as configured by the distribution
11+ developers, are too low for MongoDB and can cause a number of issues
12+ in the course of normal MongoDB operation. Generally, MongoDB should
13+ be the only user process on a system, to prevent resource contention.
1114
1215Resource Utilization
1316--------------------
@@ -18,56 +21,54 @@ section outlines the general resource utilization patterns for MongoDB.
1821Use these figures in combination with the actual information about your
1922deployment and its use to determine ideal ``ulimit`` settings.
2023
21- ``mongod``
22- ~~~~~~~~~~
23-
24- - 1 thread for each incoming connection from a client and for
25- each incoming connection from a :program:`mongod` instance in a
26- :term:`replica set <replica set>`.
27-
28- In :term:`sharded clusters <shard cluster>`, :program:`mongod`
29- instances use 1 thread for each :program:`mongos`.
24+ Generally, all :program:`mongod` and :program:`mongos` instances, like
25+ other processes:
3026
31- - 1 thread for each outgoing connection to a :program:`mongod`
32- in a replica set.
27+ - tracks each incoming connection with a file descriptor *and* a thread.
3328
34- In sharded clusters, :program:`mongod` instances use 1 file
35- descriptor for each :program:`mongos`.
29+ - tracks each internal thread or *pthread* as a system process.
3630
37- - 1 file descriptor for each incoming connection.
31+ ``mongod``
32+ ~~~~~~~~~~
3833
3934- 1 file descriptor for each data file in use by the
4035 :program:`mongod` instance.
4136
4237- 1 file descriptor for each journal file used by the
4338 :program:`mongod` instance when :setting:`journal` is ``true``.
4439
45- :program:`mongod` uses threads for a number of internal processes,
46- including :ref:`TTL collections <ttl-collections>` and replication,
47- which may require a small number of additional resources.
40+ - In replica sets, each :program:`mongod` maintains a connection to
41+ all other members of the set.
42+
43+ :program:`mongod` uses background threads for a number of internal
44+ processes, including :ref:`TTL collections <ttl-collections>` and
45+ replication, replica set health checks, which may require a small
46+ number of additional resources.
4847
4948``mongos``
5049~~~~~~~~~~
5150
52- - 1 thread for each incoming connection from a client.
53-
54- - 1 file descriptor for each incoming connection.
55-
56- - 1 file descriptor for each connection to each member of each
57- shard.
51+ In addition to the threads and file descriptors for client
52+ connections, :program:`mongos` must maintain connects to all config
53+ servers, and all shards, which includes all members of all replica
54+ sets.
5855
5956For :program:`mongos`, consider the following behaviors:
6057
6158- :program:`mongos` instances maintain a connection pool to each shard
6259 so that the :program:`mongos` can reuse connections and quickly
6360 fulfill requests without needing to create new connections.
6461
65- - The size of the connection pool is configurable with the
66- :setting:`maxConns` runtime options:
62+ - You can limit the number of incoming connections using
63+ the :setting:`maxConns` run-time option:
64+
65+ .. code-block:: javascript
6766
68- ..code-block:: javascript
67+ :option:`--maxConns <mongos --maxConns>`
6968
70- :option:`--maxConns <mongos --maxConns>`
69+ By restricting the number of incoming connections you can prevent a
70+ cascade effect where the :program:`mongos` creates too many
71+ connections on the :program:`mongod` instances.
7172
7273Review and Set Resource Limits
7374------------------------------
@@ -100,10 +101,11 @@ system limits, as in the following example:
100101
101102``ulimit`` refers to the per-*user* limitations for various
102103resources. Therefore, if your :program:`mongod` instance executes as a
103- user that is also running other processes, you might see some contention
104- for these resources. Also, be aware that the ``processes`` value
105- (i.e. ``-u``) refers to the combined number of distinct processes and
106- sub-process threads.
104+ user that is also running multiple process, or multiple
105+ :program:`mongod` process, you might see contention for these
106+ resources. Also, be aware that the ``processes`` value (i.e. ``-u``)
107+ refers to the combined number of distinct processes and sub-process
108+ threads.
107109
108110You can change ``ulimit`` settings by issuing a command in the
109111following form:
@@ -203,7 +205,7 @@ the following thresholds and settings are particularly important for
203205- ``-f`` (file size): ``unlimited``
204206- ``-t`` (cpu time): ``unlimited``
205207- ``-v`` (virtual memory): ``unlimited``
206- - ``-n`` (open files): ``21000 ``
208+ - ``-n`` (open files): ``64000 ``
207209- ``-m`` (memory size): ``unlimited``
208210- ``-u`` (processes/threads): ``32000``
209211
0 commit comments