经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MongoDB » 查看文章
mongodb占用linux大量的内存问题
来源:cnblogs  作者:_恒  时间:2021/4/6 9:42:18  对本文有异议

1.问题出现

某天我发现云服务器的内存使用达到了76%,我的乖乖这了得,我是8G的配置,上面没跑几个服务,这就很不正常。我立马用命令查看了下。

  1. top
  2. shift+m

好家伙,原来是mongodb‘独占鳌头’,占用了百分之四十多的内存。

于是我想着法儿来释放内存。

1.1 重启服务可以释放掉,这种方式估计没人会采用。

1.2 使用mongo内置命令也可以达到

  1. mongo> use admin
  2. mongo> db.runCommand({closeAllDatabases:1})

1.3 也可以直接调整

  1. shell> sysctl -w vm.drop_caches=1

等等。。

这些都是当时可以达到效果,但是过了一天,我又发现问题回到了原点,随着使用时间的增加,物理内存会逐步占用升高,治标不治本。

 

2.发现原因

 

于是我开始大量查阅在线资料。

有几篇博文讲的蛮全面(但是我又发现大量雷同文章出现)??

这篇应该是原创,时间蛮早的。

 

最后我确定了我这种小白错误原因:

官网上写的很清楚:https://docs.mongodb.com/v3.4/core/wiredtiger/index.html

  1. With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.
  2. Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:
  3. 50% of (RAM - 1 GB), or
  4. 256 MB.
  5. 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.
  6. Different representations are used for data in the WiredTiger internal cache versus the on-disk format:
  7. 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.
  8. 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.
  9. 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.
  10. Via the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes.
  11. 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

  1. storage:
    wiredTiger:
  2. engineConfig:
  3. cacheSizeGB: 2.5

2.5 代表2.5G,这这个看你的配置了和需求了。

持续观察后,发现它确实稳定到了我们的所设置的值。这就解决了,爽歪歪。

21:59:52

2021-03-22

 

原文链接:http://www.cnblogs.com/cheflone/p/14567871.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号