UNIX ulimit Settings
Most UNIX-like operating systems, including Linux and OS X, 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.
Resource Utilization
mongod and 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 ulimit settings.
Generally, all mongod and mongos instances:
- track each incoming connection with a file descriptor and a thread.
- track each internal thread or pthread as a system process.
mongod
- 1 file descriptor for each data file in use by the mongod instance.
- 1 file descriptor for each journal file used by the mongod instance when
storage.journal.enabled
is true. In replica sets, each mongod maintains a connection to all other members of the set. '
mongod uses background threads for a number of internal processes, including TTL collections, replication, and replica set health checks, which may require a small number of additional resources.
mongos
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.
For mongos, consider the following behaviors:
mongos instances maintain a connection pool to each shard so that the mongos can reuse connections and quickly fulfill requests without needing to create new connections.
You can limit the number of incoming connections using the net.maxIncomingConnections
run-time option. By restricting the number of incoming connections you can prevent a cascade effect where the mongos creates too many connections on the mongod instances.