Linux 如何重置mongodb缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10106290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:43:11  来源:igfitidea点击:

how to reset mongodb cache

linuxmongodb

提问by Oleg

Could you please tell how to reset mongodb cache to make sure that results of query are not from cache? Now I try to do it rebooting server: sudo reboot. Is there any other way? Thank you.

你能告诉我如何重置mongodb缓存以确保查询结果不是来自缓存吗?现在我尝试重新启动服务器:sudo reboot。有没有其他办法?谢谢你。

回答by AdaTheDev

MongoDB itself doesn't handle the caching. Instead, it's taken care of by the OS's virtual memory manager, as MongoDB uses Memory Mapped files. See: Mongodb.org

MongoDB 本身不处理缓存。相反,它由操作系统的虚拟内存管理器负责,因为 MongoDB 使用内存映射文件。参见:Mongodb.org

I'm no Linux guru, but for dev purposes when I wanted to ensure a completely clean cache, I did a reboot as that seemed to be what made the difference.

我不是 Linux 专家,但出于开发目的,当我想确保完全干净的缓存时,我进行了重新启动,因为这似乎是造成差异的原因。

I'm assuming you want to do this for dev/performance testing reasons rather than for production purposes too...

我假设您出于开发/性能测试的原因而不是出于生产目的也想这样做......

Update:
Check out this link: http://www.linuxask.com/questions/how-to-clear-cache-from-memory-in-linux

更新:
查看此链接:http: //www.linuxask.com/questions/how-to-clear-cache-from-memory-in-linux

回答by Taha Jahangir

Following user366534's comment, do this:

按照 user366534 的评论,执行以下操作:

  • stop mongod
  • sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
  • start mongod
  • 停止 mongod
  • sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
  • 启动mongod