Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reset mongodb cache

Tags:

linux

mongodb

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.

like image 280
Oleg Avatar asked Apr 11 '12 12:04

Oleg


2 Answers

Following user366534's comment, do this:

  • stop mongod
  • sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
  • start mongod
like image 171
Taha Jahangir Avatar answered Sep 27 '22 22:09

Taha Jahangir


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

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.

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

like image 41
AdaTheDev Avatar answered Sep 28 '22 00:09

AdaTheDev