2
2
I already posted this on StackOverflow, but it was flagged as Off-Topic. Maybe you guys are able to help me.
I'm currently doing some database benchmarking on a virtual machine running Ubuntu 12.04. I've noticed that the second time I execute a query it runs significantly faster. This ist most likely due to the OS caching that just keeps all the data in main memory. To keep the cache from screwing up my measurements I thus want to clear it between subsequent runs.
I found the following commands to achieve this on the google:
sync;echo 3 > /proc/sys/vm/drop_caches
and
sysctl -w vm.drop_caches=3
which all yield in a permission denied error even when I'm logged in as root. It seems like it is just not possible to clear the system's cache from the guest system. I guess this is because it uses the hosts cache. As I don't have access to the host I have to find a workaround. Currently I have two ideas.
First idea is to reboot the machine between runs as this clears the cache. As I want to perform a couple dozen runs I really need to automate this. So I could put a program into autostart let it perform a query and reboot and continue with the next query on the next startup. Feels like writing a virus though.
Second idea is to just flood the memory with other data. As my machine has quite a bit of RAM i would e.g. generate some large file of random data an just read it into /dev/null.
So finally my question is, has anyone a better idea to clear the cache, or maybe avoid the usage of the cache all together? Or has anyone some suggestions on how to implement one of my two ideas easily?
Thank you very much in advance, Antigo
what kind of database are you using? if you don't want your query are cached by OS, use IODIRECT – c4f4t0r – 2013-09-23T10:50:10.253