2
2
Linux ``ulimit`` Settings
3
3
=========================
4
4
5
+ .. default-domain:: mongodb
6
+
5
7
The Linux kernel provides a system to limit and control the number of
6
8
threads, 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.
11
14
12
15
Resource Utilization
13
16
--------------------
@@ -18,56 +21,54 @@ section outlines the general resource utilization patterns for MongoDB.
18
21
Use these figures in combination with the actual information about your
19
22
deployment and its use to determine ideal ``ulimit`` settings.
20
23
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:
30
26
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.
33
28
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.
36
30
37
- - 1 file descriptor for each incoming connection.
31
+ ``mongod``
32
+ ~~~~~~~~~~
38
33
39
34
- 1 file descriptor for each data file in use by the
40
35
:program:`mongod` instance.
41
36
42
37
- 1 file descriptor for each journal file used by the
43
38
:program:`mongod` instance when :setting:`journal` is ``true``.
44
39
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.
48
47
49
48
``mongos``
50
49
~~~~~~~~~~
51
50
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.
58
55
59
56
For :program:`mongos`, consider the following behaviors:
60
57
61
58
- :program:`mongos` instances maintain a connection pool to each shard
62
59
so that the :program:`mongos` can reuse connections and quickly
63
60
fulfill requests without needing to create new connections.
64
61
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
67
66
68
- ..code-block:: javascript
67
+ :option:`--maxConns <mongos --maxConns>`
69
68
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.
71
72
72
73
Review and Set Resource Limits
73
74
------------------------------
@@ -100,10 +101,11 @@ system limits, as in the following example:
100
101
101
102
``ulimit`` refers to the per-*user* limitations for various
102
103
resources. 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.
107
109
108
110
You can change ``ulimit`` settings by issuing a command in the
109
111
following form:
@@ -203,7 +205,7 @@ the following thresholds and settings are particularly important for
203
205
- ``-f`` (file size): ``unlimited``
204
206
- ``-t`` (cpu time): ``unlimited``
205
207
- ``-v`` (virtual memory): ``unlimited``
206
- - ``-n`` (open files): ``21000 ``
208
+ - ``-n`` (open files): ``64000 ``
207
209
- ``-m`` (memory size): ``unlimited``
208
210
- ``-u`` (processes/threads): ``32000``
209
211
0 commit comments