I am currently benchmarking a database on a virtual machine running Ubuntu 12.04. I noticed that the second time I execute the request, it runs much faster. This is most likely due to OS caching, which simply stores all the data in main memory. So that the cache does not freeze my measurements, I therefore want to clear it of subsequent runs.
I found the following commands to achieve this on google:
sync;echo 3 > /proc/sys/vm/drop_caches
and
sysctl -w vm.drop_caches=3
which all give out in the resolved error, even when I am registered as root. It seems that it is simply impossible to clear the system cache from the guest system. I think this is because it uses the host cache. Since I do not have access to the host, I need to find a workaround. I currently have two ideas.
The first idea is to restart the computer between runs, as this clears the cache. Since I want to do a few dozen runs, I really need to automate this. Therefore, I could put the program in autostart so that it fulfills the request and reboots and continues the next request at the next start. It looks like I'm writing a virus.
The second idea is to simply fill the memory with other data. Since my machine has quite a lot of RAM, I would, for example, generate some large random data file just by reading it in / dev / null.
So finally, my question is: does anyone have a better way to clear the cache or maybe avoid using the cache? Or does anyone have suggestions on how easy it is to implement one of my two ideas?
Thank you very much in advance Antigo
source share