My case is that I run several queries in Mongo and measure the response time. I know that Mongo uses Memory Mapped files and cache some data in RAM.
If I create an index and run a query the execution time is 2,07 seconds. When I run the qeury again the execution time is 0,017 seconds.
This means that the file is mapped into memory by the OS on the first access and the OS will keep it in cache until it decides to page it out.
Because I want to make some benchmarks I want somehow to remove the mapped results from memory.
free -g: total used free shared buffers cached Mem: 29 29 0 0 0 29 -/+ buffers/cache: 0 29 Swap: 0 0 0
db.collection.getPlanCache().clear() but it doesnt work.
Then I try:
sudo service mongod stop
I reboot my machine
sync; echo 3 > /proc/sys/vm/drop_caches sudo service mongod start
total used free shared buffers cached Mem: 29 0 0 0 0 0 -/+ buffers/cache: 0 29 Swap: 0 0 0
In above it seems that cache is free now. But when I execute again the query the execution time is 0,017 seconds. It seems that mongo has manage to cache or preserve the data somewhere. The desired execution time would be 2,07 seconds as I clear the cache.
Can anyone tell me how I can actually delete the cached results in Mongo?