1.問題出現
某天我發現云服務器的記憶體使用達到了76%,我的乖乖這了得,我是8G的配置,上面沒跑幾個服務,這就很不正常,我立馬用命令查看了下,
top
shift+m
好家伙,原來是mongodb‘獨占鰲頭’,占用了百分之四十多的記憶體,
于是我想著法兒來釋放記憶體,
1.1 重啟服務可以釋放掉,這種方式估計沒人會采用,
1.2 使用mongo內置命令也可以達到
mongo> use admin mongo> db.runCommand({closeAllDatabases:1})
1.3 也可以直接調整
shell> sysctl -w vm.drop_caches=1
等等,,
這些都是當時可以達到效果,但是過了一天,我又發現問題回到了原點,隨著使用時間的增加,物理記憶體會逐步占用升高,治標不治本,
2.發現原因
于是我開始大量查閱在線資料,
有幾篇博文講的蠻全面(但是我又發現大量雷同文章出現)??
這篇應該是原創,時間蠻早的,
最后我確定了我這種小白錯誤原因:
官網上寫的很清楚:https://docs.mongodb.com/v3.4/core/wiredtiger/index.html
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache. Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either: 50% of (RAM - 1 GB), or 256 MB. By default, WiredTiger uses Snappy block compression for all collections and prefix compression for all indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation. Different representations are used for data in the WiredTiger internal cache versus the on-disk format: Data in the filesystem cache is the same as the on-disk format, including benefits of any compression for data files. The filesystem cache is used by the operating system to reduce disk I/O. Indexes loaded in the WiredTiger internal cache have a different data representation to the on-disk format, but can still take advantage of index prefix compression to reduce RAM usage. Index prefix compression deduplicates common prefixes from indexed fields. Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server. Via the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes. To adjust the size of the WiredTiger internal cache, seestorage.wiredTiger.engineConfig.cacheSizeGB and --wiredTigerCacheSizeGB. Avoid increasing the WiredTiger internal cache size above its default value
3.解決方式
原來是忽略這個原因,默認會使用50%的記憶體,
根據官方說的改改組態檔吧,加上這一段,
mongod.conf
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 2.5
2.5 代表2.5G,這這個看你的配置了和需求了,
持續觀察后,發現它確實穩定到了我們的所設定的值,這就解決了,爽歪歪,
21:59:52
2021-03-22
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/271158.html
標籤:其它
下一篇:達夢體系結構與運維管理
