Example Analysis of MongoDB taking up too much memory and frequently crashing
This article will explain in detail the example analysis of MongoDB's excessive memory usage and frequent crashes. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
Starting with MongoDB 3.4, the default WiredTiger internal cache size is the larger of:
50%(RAM-1 GB), or 256 MB
For example, on a system with a total of 4GB RAM, WiredTiger cache will use 1.5GB RAM ().
Conversely, a system with 1.25 GB of total memory would allocate 256 MB for WiredTiger cache, since that's more than half of total RAM minus 1 GB ().
// 4GB
0.5 * (4 GB - 1 GB) = 1.5 GB
// 1.25GB
0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB
After reading the documentation, I checked my memory usage
$ free -h#does not start mongod total used freeMem: 3.7G 2.4G 1.3G #Start mongod total used freeMem: 3.7G 1.8G 364M
It's full of memory.
MongoDB takes up too much memory and is killed by the system, so there is downtime.
solution
Add two parameters
Modify configuration mongodb.conf
#The maximum amount of memory allocated for cache; default is 1/2#of physical RAM wiredTigerCacheSizeGB wiredTigerCacheSizeGB=0.5#Maximum simultaneous connections, default 100000About "MongoDB takes up too much memory and frequently crashes example analysis" This article is shared here, I hope the above content can have some help for everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.