FAQ: MongoDB Diagnostics
On this page
- Where can I find information about a
mongodprocess that stopped running unexpectedly?
- Does TCP
keepalivetime affect MongoDB Deployments?
- Why does MongoDB log so many “Connection Accepted” events?
- What tools are available for monitoring MongoDB?
- Memory Diagnostics for the MMAPv1 Storage Engine
- Memory Diagnostics for the WiredTiger Storage Engine
- Sharded Cluster Diagnostics
This document provides answers to common diagnostic questions and issues.
mongod shuts down unexpectedly on a UNIX or UNIX-based platform, and if
mongod fails to log a shutdown or error message, then check your system logs for messages pertaining to MongoDB. For example, for logs located in
/var/log/messages, use the following commands:
If you experience network timeouts or socket errors in communication between clients and servers, or between members of a sharded cluster or replica set, check the TCP keepalive value for the affected systems.
Many operating systems set this value to
7200 seconds (two hours) by default. For MongoDB, you will generally experience better results with a shorter keepalive value, on the order of
120 seconds (two minutes).
If your MongoDB deployment experiences keepalive-related issues, you must alter the keepalive value on all affected systems. This includes all machines running
mongos processes and all machines hosting client processes that connect to MongoDB.
To view the keepalive setting on Linux, use one of the following commands:
The value is measured in seconds.
Although the setting name includes
tcp_keepalive_timevalue applies to both IPv4 and IPv6.
To change the
tcp_keepalive_timevalue, you can use one of the following commands, supplying a <value> in seconds:
These operations do not persist across system reboots. To persist the setting, add the following line to
/etc/sysctl.conf, supplying a <value> in seconds, and reboot the machine:
To view the keepalive setting on Windows, issue the following command:
The registry value is not present by default. The system default, used if the value is absent, is
To change the
KeepAliveTimevalue, use the following command in an Administrator Command Prompt, where
<value>is expressed in hexadecimal (e.g.
Windows users should consider the Windows Server Technet Article on KeepAliveTime for more information on setting keepalive for MongoDB deployments on Windows systems. Keepalive values greater than or equal to 600000 milliseconds (10 minutes) will be ignored by
To view the keepalive setting on macOS, issue the following command:
The value is measured in milliseconds.
To change the
net.inet.tcp.keepidlevalue, you can use the following command, supplying a <value> in milliseconds:
This operation does not persist across system reboots, and must be set each time your system reboots. See your operating system’s documentation for instructions on setting this value persistently. Keepalive values greater than or equal to
600000milliseconds (10 minutes) will be ignored by
In macOS 10.15 Catalina, Apple no longer allows for configuration of the
If you see a very large number of connection and re-connection messages in your MongoDB log, then clients are frequently connecting and disconnecting to the MongoDB server. This is normal behavior for applications that do not use request pooling, such as CGI. Consider using FastCGI, an Apache Module, or some other kind of persistent application server to decrease the connection overhead.
The MongoDB Cloud Manager and Ops Manager, an on-premise solution available in MongoDB Enterprise Advanced include monitoring functionality, which collects data from running MongoDB deployments and provides visualization and alerts based on that data.
A full list of third-party tools is available as part of the Monitoring for MongoDB documentation.
Always configure systems to have swap space. Without swap, your system may not be reliant in some situations with extreme memory constraints, memory leaks, or multiple programs using the same memory. Think of the swap space as something like a steam release valve that allows the system to release extra pressure without affecting the overall functioning of the system.
Nevertheless, systems running MongoDB do not need swap for routine operation. Database files are memory-mapped and should constitute most of your MongoDB memory use. Therefore, it is unlikely that
mongod will ever use any swap space in normal operation. The operating system will release memory from the memory mapped files without needing swap and MongoDB can write data to the data files without needing the swap system.
The working set is the portion of your data that clients access most often.
Your working set should stay in memory to achieve good performance. Otherwise many random disk IO’s will occur, and unless you are using SSD, this can be quite slow.
One area to watch specifically in managing the size of your working set is index access patterns. If you are inserting into indexes at random locations (as would happen with id’s that are randomly generated by hashes), you will continually be updating the whole index. If instead you are able to create your id’s in approximately ascending order (for example, day concatenated with a random id), all the updates will occur at the right side of the b-tree and the working set size for index pages will be much smaller.
It is fine if databases and thus virtual size are much larger than RAM.
The amount of RAM you need depends on several factors, including but not limited to:
- The relationship between database storage and working set.
- The operating system’s cache strategy for LRU (Least Recently Used)
- The impact of journaling
- The number or rate of page faults and other MongoDB Cloud Manager gauges to detect when you need more RAM
- Each database connection thread will need up to 1 MB of RAM.
MongoDB defers to the operating system when loading data into memory from disk. It simply memory maps all its data files and relies on the operating system to cache data. The OS typically evicts the least-recently-used data from RAM when it runs low on memory. For example if clients access indexes more frequently than documents, then indexes will more likely stay in RAM, but it depends on your particular usage.
To calculate how much RAM you need, you must calculate your working set size, or the portion of your data th